-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72473ab
commit de983a9
Showing
5 changed files
with
143 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Lockless-Queue\Lockless-Queue.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
using LocklessQueues; | ||
using System; | ||
using System.Collections.Generic; | ||
using SysConcurrentQueue = System.Collections.Concurrent.ConcurrentQueue<long>; | ||
|
||
namespace Benchmark | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
BenchmarkRunner.Run<Benchmarks>(); | ||
Console.ReadLine(); | ||
} | ||
} | ||
|
||
[MemoryDiagnoser] | ||
public class Benchmarks | ||
{ | ||
const int COUNT = 128; | ||
|
||
readonly ConcurrentQueue<long> _concurrentQueue; | ||
readonly SysConcurrentQueue _systemConcurrentQueue; | ||
readonly MPSCQueue<long> _mpscQueue; | ||
readonly SPSCQueue<long> _spscQueue; | ||
readonly Queue<long> _queue; | ||
|
||
public Benchmarks() | ||
{ | ||
_concurrentQueue = new ConcurrentQueue<long>(COUNT, true); | ||
_systemConcurrentQueue = new SysConcurrentQueue(); | ||
_mpscQueue = new MPSCQueue<long>(COUNT); | ||
_spscQueue = new SPSCQueue<long>(COUNT); | ||
_queue = new Queue<long>(COUNT); | ||
} | ||
|
||
[Benchmark] | ||
public void ConcurrentQueue() | ||
{ | ||
// ADD values | ||
for (int i = 0; i < COUNT; i++) | ||
_concurrentQueue.TryEnqueue(i); | ||
|
||
for (int i = 0; i < COUNT; i++) | ||
_concurrentQueue.TryDequeue(out long result); | ||
|
||
_concurrentQueue.Clear(); | ||
} | ||
|
||
[Benchmark] | ||
public void SysConcurrentQueue() | ||
{ | ||
// ADD values | ||
for (int i = 0; i < COUNT; i++) | ||
_systemConcurrentQueue.Enqueue(i); | ||
|
||
for (int i = 0; i < COUNT; i++) | ||
_systemConcurrentQueue.TryDequeue(out long result); | ||
|
||
_systemConcurrentQueue.Clear(); | ||
} | ||
|
||
[Benchmark] | ||
public void MPSCQueue() | ||
{ | ||
// ADD values | ||
for (int i = 0; i < COUNT; i++) | ||
_mpscQueue.TryEnqueue(i); | ||
|
||
for (int i = 0; i < COUNT; i++) | ||
_mpscQueue.TryDequeue(out long result); | ||
|
||
_mpscQueue.Clear(); | ||
} | ||
|
||
[Benchmark] | ||
public void SPSCQueue() | ||
{ | ||
// ADD values | ||
for (int i = 0; i < COUNT; i++) | ||
_spscQueue.TryEnqueue(i); | ||
|
||
for (int i = 0; i < COUNT; i++) | ||
_spscQueue.TryDequeue(out long result); | ||
|
||
_spscQueue.Clear(); | ||
} | ||
|
||
[Benchmark] | ||
public void Queue() | ||
{ | ||
// ADD values | ||
for (int i = 0; i < COUNT; i++) | ||
_queue.Enqueue(i); | ||
|
||
for (int i = 0; i < COUNT; i++) | ||
_queue.TryDequeue(out long result); | ||
|
||
_queue.Clear(); | ||
} | ||
} | ||
} |
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