-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmark.cs
More file actions
executable file
·43 lines (35 loc) · 1.36 KB
/
Benchmark.cs
File metadata and controls
executable file
·43 lines (35 loc) · 1.36 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
using System;
using System.Diagnostics;
using ShortestPathTAB.Graph;
using ShortestPathTAB.Graph.Solve;
namespace ShortestPathTAB
{
class Benchmark
{
public void Run() {
Graph.Graph g = new Graph.Graph();
Random rnd = new Random(100);
int vertCount = (int)char.MaxValue;
int edgePerVert = 2;
Console.WriteLine("Building graph of " + vertCount + " verices and " + vertCount * edgePerVert + " edges...");
Stopwatch s = new Stopwatch();
s.Start();
for (int i = 0; i < vertCount; i++) {
g.AddVertex(new Vertex((char)i));
}
Vertex[] vertices = g.GetVertices();
foreach (Vertex v in vertices) {
for (int i = 0; i < edgePerVert; i++) {
g.AddEdge(new Edge(v, vertices[rnd.Next(0, vertices.Length - 1)], rnd.Next(1, 30)));
}
}
Console.WriteLine("Building graph took: " + s.ElapsedMilliseconds + "ms");
s.Reset();
s.Start();
Solver solv = new Dijkstra(g);
solv.Solve(vertices[0]);
Console.WriteLine("solving took: " + s.ElapsedMilliseconds + "ms");
System.IO.File.WriteAllText("Benchmark.txt", solv.GetSolvingTable());
}
}
}