-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
59 lines (50 loc) · 1.79 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using BenchmarkDotNet.Running;
using GraphQL.Http;
namespace GraphQL.Benchmarks
{
class Program
{
public static void Main()
{
BenchmarkRunner.Run<GraphQL_BatchedIOPerformance>();
// RunTests().Wait();
}
private static async Task RunTests()
{
TestDataGenerator.InitializeDb();
var writer = new DocumentWriter(true);
var results = new List<ExecutionResult>();
results.Add(await RunTest("Baseline", _ => _.Baseline()));
results.Add(await RunTest("DataLoader", _ => _.DataLoader()));
results.Add(await RunTest("BatchResolver", _ => _.BatchResolver()));
for (var i = 0; i < results.Count; i++)
{
File.WriteAllText("log/result" + i + ".json", writer.Write(results[i]));
}
}
private static async Task<ExecutionResult> RunTest(string name, Func<GraphQL_BatchedIOPerformance, Task<ExecutionResult>> func)
{
try
{
var harness = new GraphQL_BatchedIOPerformance();
harness.Setup();
Console.WriteLine($"Running {name}: ");
var sw = Stopwatch.StartNew();
var result = await func(harness);
Console.WriteLine($"{name} finished in {sw.ElapsedMilliseconds}ms");
harness.Cleanup();
return result;
}
catch (Exception e)
{
Console.WriteLine($"Oops, error occurred: {e}");
}
return null;
}
}
}