-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (101 loc) · 3.75 KB
/
Program.cs
File metadata and controls
111 lines (101 loc) · 3.75 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// #define SIMPLE_CLI_TESTING
#if SIMPLE_CLI_TESTING
using System.Diagnostics;
#endif
namespace InteropExperiments;
internal static class Program
{
internal static void Main(string[] args)
{
if (args.Length < 1)
{
throw new InvalidOperationException("Missing 1 required argument: A file path to a json-formatted IV MTR feed.");
}
#if SIMPLE_CLI_TESTING
int? count = null;
if (args.Length == 3 && args[1] == "--count" && int.TryParse(args[2], out int parsedCount))
{
count = parsedCount;
}
long csOpenTimeMs;
long csElapsedMs;
double csAvg;
int csidx = 0;
Stopwatch csharpStopwatch = Stopwatch.StartNew();
using CsharpIvMtrFeeder csharpReader = CsharpIvMtrFeeder.OpenFile(args[0]);
{
csOpenTimeMs = csharpStopwatch.ElapsedMilliseconds;
csElapsedMs = csharpStopwatch.ElapsedMilliseconds;
try
{
if (count != 0)
{
csharpStopwatch.Restart();
foreach (ScanResult scan in csharpReader)
{
Console.WriteLine($"Read scan[{csidx}] in {csharpStopwatch.ElapsedMilliseconds}ms. IMB: {scan.Imb}, MailPhase: {scan.MailPhase}");
csidx++;
if (count.HasValue)
{
if (csidx >= count)
{
break;
}
}
csElapsedMs += csharpStopwatch.ElapsedMilliseconds;
csharpStopwatch.Restart();
}
}
}
finally
{
csAvg = csElapsedMs / (csidx == 0 ? 1 : csidx);
}
}
Thread.Sleep(1000);
long zigOpenTimeMs;
long zigElapsedMs;
double zigAvg;
int zidx = 0;
Stopwatch zigStopwatch = Stopwatch.StartNew();
using ZigIvMtrFeedReader zigReader = ZigIvMtrFeedReader.OpenFile(args[0]);
{
zigOpenTimeMs = zigStopwatch.ElapsedMilliseconds;
zigElapsedMs = zigStopwatch.ElapsedMilliseconds;
try
{
if (count != 0)
{
zigStopwatch.Restart();
foreach (ScanResult scan in zigReader)
{
Console.WriteLine($"Read scan[{zidx}] in {zigStopwatch.ElapsedMilliseconds}ms. IMB: {scan.Imb}, MailPhase: {scan.MailPhase}");
zidx++;
if (count.HasValue)
{
if (zidx >= count)
{
break;
}
}
zigElapsedMs += zigStopwatch.ElapsedMilliseconds;
zigStopwatch.Restart();
}
}
}
finally
{
zigAvg = zigElapsedMs / (zidx == 0 ? 1 : zidx);
}
}
Console.WriteLine("------------------------------------------------------------------------------------");
Console.WriteLine($"Opened C# reader in {csOpenTimeMs}ms");
Console.WriteLine($"C# total time: {csElapsedMs}ms. Processed: {csidx} Avg processing time: {csAvg}ms");
Console.WriteLine($"Opened zig reader in {zigOpenTimeMs}ms");
Console.WriteLine($"Zig total time: {zigElapsedMs}ms. Processed: {zidx} Avg processing time: {zigAvg}ms");
#else
Benchmarks benchmarks = new(args[0], [1000, 10000, 20000, 40000]);
benchmarks.Run();
#endif
}
}