-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ormance test
- Loading branch information
Showing
7 changed files
with
217 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.10.8" /> | ||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.2.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\PooledStream\PooledStream.csproj" /> | ||
</ItemGroup> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.10.8" /> | ||
<PackageReference Include="CodeProject.ObjectPool" Version="3.1.1" /> | ||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.2.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\PooledStream\PooledStream.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace PooledStream.Benchmark | ||
{ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Diagnosers; | ||
using System.Buffers; | ||
using Microsoft.IO; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.Linq; | ||
using ObjectMemoryStream = CodeProject.ObjectPool.Specialized.MemoryStreamPool; | ||
[MemoryDiagnoser] | ||
public class StreamPrallelBenchmark | ||
{ | ||
[Params(5, 10)] | ||
public int ParallelNum{get;set;} | ||
[Params(1000)] | ||
public int DataSize{get;set;} | ||
[Params(10000)] | ||
public int MaxLoop{get;set;} | ||
[Benchmark(Baseline=true)] | ||
public void NormalStreamParallel() | ||
{ | ||
var data = new byte[DataSize]; | ||
Task.WhenAll(Enumerable.Range(0, ParallelNum) | ||
.Select(async (idx) => { | ||
for(int i = 0;i<MaxLoop/ParallelNum;i++) | ||
{ | ||
using(var stm = new MemoryStream(DataSize)) | ||
{ | ||
await stm.WriteAsync(data, 0, data.Length).ConfigureAwait(false); | ||
} | ||
} | ||
return idx; | ||
})).Wait(); | ||
} | ||
[Benchmark] | ||
public void PooledStreamParallel() | ||
{ | ||
var data = new byte[DataSize]; | ||
Task.WhenAll(Enumerable.Range(0, ParallelNum) | ||
.Select(async (idx) => { | ||
for(int i = 0;i<MaxLoop/ParallelNum;i++) | ||
{ | ||
using(var stm = new PooledMemoryStream(ArrayPool<byte>.Shared, data.Length)) | ||
{ | ||
await stm.WriteAsync(data, 0, data.Length).ConfigureAwait(false); | ||
} | ||
} | ||
return idx; | ||
})).Wait(); | ||
} | ||
[Benchmark] | ||
public void ObjectPoolParallel() | ||
{ | ||
var data = new byte[DataSize]; | ||
var pool = ObjectMemoryStream.Instance; | ||
Task.WhenAll(Enumerable.Range(0, ParallelNum) | ||
.Select(async (idx) => { | ||
for(int i = 0;i<MaxLoop;i++) | ||
{ | ||
using(var stm = pool.GetObject()) | ||
{ | ||
await stm.MemoryStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); | ||
} | ||
} | ||
return idx; | ||
})).Wait(); | ||
} | ||
[Benchmark] | ||
public void RecyclableStreamParallel() | ||
{ | ||
var data = new byte[DataSize]; | ||
var manager = new RecyclableMemoryStreamManager(); | ||
Task.WhenAll(Enumerable.Range(0, ParallelNum) | ||
.Select(async (idx) => { | ||
for(int i = 0;i<MaxLoop;i++) | ||
{ | ||
using(var stm = manager.GetStream()) | ||
{ | ||
await stm.WriteAsync(data, 0, data.Length).ConfigureAwait(false); | ||
} | ||
} | ||
})).Wait(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters