forked from drorgl/ForBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingPlatform.cs
More file actions
59 lines (48 loc) · 1.47 KB
/
TestingPlatform.cs
File metadata and controls
59 lines (48 loc) · 1.47 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace FormatBenchmarks
{
public class TestingPlatform
{
public class TestResults
{
public int ParameterCount;
public long ElapsedMilliseconds;
public Exception Exception;
}
public static TestResults TestFormat(int formatCount, int iterations, Action<string,object[]> action)
{
object[] valuesdict = new object[formatCount];
string template = "hello ";
for (int i = 0; i < formatCount; i++)
{
template += "{" + i + "} text112";
valuesdict[i] = i;
}
Stopwatch sw = new Stopwatch();
//prime the string format, so it will be more realistic
action(template, valuesdict);
for (var i = 0; i < iterations; i++)
{
sw.Stop();
for (int fc = 0; fc < formatCount; fc++)
{
valuesdict[fc] = i;
}
sw.Start();
action(template, valuesdict);
sw.Stop();
}
TestResults tr = new TestResults
{
ParameterCount = formatCount,
ElapsedMilliseconds = sw.ElapsedMilliseconds
};
return tr;
}
}
}