This repository was archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (61 loc) · 2.21 KB
/
Copy pathProgram.cs
File metadata and controls
69 lines (61 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define HIGH_PRECISION
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using System;
using System.Diagnostics;
using System.Threading;
namespace AdvancedMultithreadingLab
{
internal class Program
{
private static void Main( string[] args )
{
RunTest<TestMyConcurrentQueue>();
RunTest<TestMyConcurrentStack>();
RunTest<TestSystemConcurrentStack>();
RunTest<TestSystemConcurrentQueue>();
RunTest<TestSystemConcurrentBag>();
RunTest<TestBlockingCollection>();
}
static void RunTest<T>() where T : TestCollectionBase, new()
{
#if HIGH_PRECISION
ManualConfig config = new ManualConfig();
config.Add( new Job( "DefaultJob", RunMode.Default, EnvMode.RyuJitX64 )
{
Env = { Runtime = Runtime.Clr },
Accuracy = { MaxStdErrRelative = 0.05, RemoveOutliers = true },
} );
config.Add( ConsoleLogger.Default );
config.Add( CsvExporter.Default, HtmlExporter.Default );
var summary = BenchmarkRunner.Run<T>( config );
#else
for ( int threads = 1; threads <= 2; threads++ )
{
T test = new T() { Threads = threads };
test.Setup();
test.RunTests();
GC.Collect();
Stopwatch stopwatch = Stopwatch.StartNew();
const int n = 10;
for ( int i = 0; i < n; i++ )
{
test.RunTests();
}
GC.Collect();
stopwatch.Stop();
test.Dispose();
long operations = n * TestCollectionBase.Iterations;
double ns = ((double) stopwatch.ElapsedTicks / operations) / (1E-9 * Stopwatch.Frequency);
Console.WriteLine( $"{typeof( T ).Name} with {threads} threads on each end: {ns:0.0} ns/op, {threads * 1E3 / ns:0.0} MT/s" );
}
#endif
}
}
}