-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBenchmark.cs
33 lines (29 loc) · 852 Bytes
/
Benchmark.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
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace it.Actions
{
public class Benchmark
{
public void RunTheMethod(Action action)
{
// Create new stopwatch.
Stopwatch stopwatch = new Stopwatch();
// Begin timing.
stopwatch.Start();
// Do something.
for (int i = 0; i < 10000000; i++)
{
action();
}
// Stop timing.
stopwatch.Stop();
// Write result.
Console.WriteLine("Total time: {0}", stopwatch.Elapsed.TotalMilliseconds);
Console.WriteLine("Avg time: {0}", stopwatch.Elapsed.TotalMilliseconds / 10000000.0);
}
}
}