-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
90 lines (71 loc) · 2.74 KB
/
Program.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using bench;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
namespace benchtool_dotnetcore
{
class Program
{
public static void Main(string[] args)
{
var loopCount = "5";
IBench bench = null;
Thread runnerThread = null;
BenchResult<Object> result = null;
int executionCount = 5;
List<BenchResult<Object>> results = new List<BenchResult<object>>();
if(args?.Length >= 2){
loopCount = args[1];
int benchType = int.Parse(args[0]);
if(args?.Length >= 3 )
{
executionCount = int.Parse(args[2]);
}
switch(benchType){
case 1:
bench = new SimpleFibonacciLoopBench();
runnerThread = new Thread(()=>{
for(int i = 0; i < executionCount; i++){
result = bench.run(loopCount);
results.Add(result);
}
});
break;
default:
bench = new SimpleFibonacciBench();
runnerThread = new Thread(()=>{
for(int i = 0; i < executionCount; i++){
result = bench.run(loopCount);
results.Add(result);
}
}, 1024 * 1024 * 1024);//changes the thread stack size for the recursive
break;
}
}
else
{
bench = new SimpleFibonacciLoopBench();
runnerThread = new Thread(()=>{
for(int i = 0; i < executionCount; i++){
result = bench.run(loopCount);
results.Add(result);
}
});
}
runnerThread.Start();
runnerThread.Join();
var totalMs = results
.Sum( r => r.RunningMilliseconds);
long averageMs = totalMs / executionCount;
object rawResult = results[0].value;
bool resultsOk = results.All( r => rawResult.ToString().Equals(r.value.ToString()));
if(!resultsOk)
{
Console.WriteLine("Execution problem, not all results are ok ='(");
Environment.Exit(-1);
}
Console.Write($"{averageMs} {rawResult.ToString()}");
}
}
}