-
Notifications
You must be signed in to change notification settings - Fork 0
/
GamePerformanceTest.cs
50 lines (41 loc) · 1.48 KB
/
GamePerformanceTest.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
using ReachTheFlag.ExtensionMethods;
using ReachTheFlag.Game;
using ReachTheFlag.Logic;
using System.Diagnostics;
namespace ReachTheFlag
{
public class GamePerformanceTest
{
private ReachTheFlagGame _game;
public GamePerformanceTest(ReachTheFlagGame game)
{
_game = game;
}
public void CalculateAndDisplayAverageRuntimes(int iterationsCount)
{
Console.WriteLine($"Average runtime for algorithms ({iterationsCount} iterations):");
foreach (SolverStrategy strategy in Enum.GetValues(typeof(SolverStrategy)))
{
if (strategy == SolverStrategy.UserInput) continue;
double averageRuntime = 0;
for (var i = 0; i < iterationsCount; i++)
{
var watch = new Stopwatch();
watch.Start();
_game.Solve(strategy);
watch.Stop();
averageRuntime += watch.Elapsed.TotalSeconds;
}
averageRuntime /= iterationsCount;
displayAverageRuntime(strategy.DisplayName(), averageRuntime);
}
}
private void displayAverageRuntime(string strategyName, double avg)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{strategyName}:\t");
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"{avg}s\n");
}
}
}