懒得勤快 2 年之前
父節點
當前提交
06b943dd13
共有 4 個文件被更改,包括 38 次插入9 次删除
  1. 4 1
      BenchmarkTest/BenchmarkTest.csproj
  2. 3 8
      BenchmarkTest/Program.cs
  3. 30 0
      BenchmarkTest/StreamTest.cs
  4. 1 0
      Masuit.Tools.sln

+ 4 - 1
BenchmarkTest/BenchmarkTest.csproj

@@ -4,11 +4,14 @@
     <OutputType>Exe</OutputType>
     <TargetFramework>net7.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
 
   <ItemGroup>
     <PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
   </ItemGroup>
 
+  <ItemGroup>
+    <ProjectReference Include="..\Masuit.Tools.Core\Masuit.Tools.Core.csproj" />
+  </ItemGroup>
+
 </Project>

+ 3 - 8
BenchmarkTest/Program.cs

@@ -1,9 +1,4 @@
-using BenchmarkDotNet.Attributes;
-using BenchmarkDotNet.Running;
+using BenchmarkDotNet.Running;
+using BenchmarkTest;
 
-BenchmarkRunner.Run<TestClass>();
-
-[MemoryDiagnoser]
-public class TestClass
-{
-}
+BenchmarkRunner.Run<StreamTest>();

+ 30 - 0
BenchmarkTest/StreamTest.cs

@@ -0,0 +1,30 @@
+using BenchmarkDotNet.Attributes;
+using Masuit.Tools.Systems;
+
+namespace BenchmarkTest;
+
+[MemoryDiagnoser]
+public class StreamTest
+{
+    [Benchmark]
+    public void MemoryStreamTest()
+    {
+        foreach (var file in new DirectoryInfo(@"D:\images\emotion\emoji").EnumerateFiles())
+        {
+            using var stream = file.OpenRead();
+            using var ms = new MemoryStream();
+            stream.CopyTo(ms);
+        }
+    }
+
+    [Benchmark]
+    public void PooledMemoryStreamTest()
+    {
+        foreach (var file in new DirectoryInfo(@"D:\images\emotion\emoji").EnumerateFiles())
+        {
+            using var stream = file.OpenRead();
+            using var ms = new PooledMemoryStream();
+            stream.CopyTo(ms);
+        }
+    }
+}

+ 1 - 0
Masuit.Tools.sln

@@ -98,6 +98,7 @@ Global
 		{61430D45-3808-49B5-BDF3-4536DA399DD4} = {E0B8FBD1-A28A-4420-9DE2-6BD06035CBAC}
 		{99185F12-DFAD-4DB8-A2C4-C7E9700C0A31} = {E0B8FBD1-A28A-4420-9DE2-6BD06035CBAC}
 		{AB9F4635-0ACB-4E5E-8E1B-431E0818CF60} = {E0B8FBD1-A28A-4420-9DE2-6BD06035CBAC}
+		{0599ACF0-8495-4E72-AB5E-B7446A5C413A} = {E0B8FBD1-A28A-4420-9DE2-6BD06035CBAC}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {B57FDA8F-95CF-478B-A0A8-7FF0F01CCFAB}