Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
119 lines (97 loc) · 2.89 KB
/
Copy pathProgram.cs
File metadata and controls
119 lines (97 loc) · 2.89 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
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Northwind.Perf;
using ServiceStack.Logging;
using ServiceStack.OrmLite.TestsPerf.Scenarios.Northwind;
using ServiceStack.OrmLite.TestsPerf.Scenarios.OrmLite;
namespace ServiceStack.OrmLite.TestsPerf
{
class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
const long DefaultIterations = 1;
static readonly List<long> BatchIterations = new List<long> { 100, 1000, 5000, 20000, /*100000, 250000, 1000000, 5000000*/ };
//static readonly List<long> BatchIterations = new List<long> { 1, 10, 100 };
static List<DatabaseScenarioBase> GetUseCases()
{
return new List<DatabaseScenarioBase>
{
//new InsertModelWithFieldsOfDifferentTypesPerfScenario(),
//new InsertSampleOrderLineScenario(),
//new SelectOneModelWithFieldsOfDifferentTypesPerfScenario(),
//new SelectOneSampleOrderLineScenario(),
//new SelectManyModelWithFieldsOfDifferentTypesPerfScenario(),
//new SelectManySampleOrderLineScenario(),
new InsertNorthwindDataScenario(),
};
}
static void Main(string[] args)
{
try
{
foreach (var configRun in OrmLiteScenrioConfig.DataProviderConfigRuns())
{
Console.WriteLine("\n\nStarting config run {0}...", configRun);
if (args.Length == 1 && args[0] == "csv")
RunBatch(configRun);
else
RunInteractive(configRun, args);
}
Console.ReadKey();
}
catch (Exception ex)
{
Log.Error("Error running perfs", ex);
throw;
}
}
private static void RunBatch(OrmLiteConfigRun configRun)
{
Console.Write(";");
var useCases = GetUseCases();
useCases.ForEach(uc => Console.Write("{0};", uc.GetType().Name));
Console.WriteLine();
BatchIterations.ForEach(iterations => {
Console.Write("{0};", iterations);
useCases.ForEach(uc => {
configRun.Init(uc);
// warmup
uc.Run();
GC.Collect();
Console.Write("{0};", Measure(uc.Run, iterations));
});
Console.WriteLine();
});
}
private static void RunInteractive(OrmLiteConfigRun configRun, string[] args)
{
long iterations = DefaultIterations;
if (args.Length != 0)
iterations = long.Parse(args[0]);
Console.WriteLine("Running {0} iterations for each use case.", iterations);
var useCases = GetUseCases();
useCases.ForEach(uc => {
configRun.Init(uc);
// warmup
uc.Run();
GC.Collect();
var avgMs = Measure(uc.Run, iterations);
Console.WriteLine("{0}: Avg: {1}ms", uc.GetType().Name, avgMs);
});
}
private static decimal Measure(Action action, decimal iterations)
{
GC.Collect();
var stopWatch = new Stopwatch();
stopWatch.Start();
var begin = stopWatch.ElapsedMilliseconds;
for (var i = 0; i < iterations; i++)
{
action();
}
var end = stopWatch.ElapsedMilliseconds;
return (end - begin) / iterations;
}
}
}