3using System.Diagnostics;
4using System.Globalization;
14 private readonly SortedDictionary<string, bool> tests =
new SortedDictionary<string, bool>();
15 private readonly SortedDictionary<long, bool> complexities =
new SortedDictionary<long, bool>();
16 private readonly Dictionary<string, Dictionary<long, long>> ticks =
new Dictionary<string, Dictionary<long, long>>();
17 private readonly
object syncObject =
new object();
18 private readonly Stopwatch watch;
25 this.watch =
new Stopwatch();
36 lock (this.syncObject)
38 return this.GetTestsLocked();
43 private string[] GetTestsLocked()
45 string[] Result =
new string[this.tests.Count];
46 this.tests.Keys.CopyTo(Result, 0);
57 lock (this.syncObject)
59 return this.GetComplexitiesLocked();
64 private long[] GetComplexitiesLocked()
66 long[] Result =
new long[this.complexities.Count];
67 this.complexities.Keys.CopyTo(Result, 0);
75 public double?[,]
Ticks => this.GetScaledTicks(1);
81 public double?[,]
Minutes => this.GetScaledTicks(1.0 / (Stopwatch.Frequency * 60.0));
87 public double?[,]
Seconds => this.GetScaledTicks(1.0 / Stopwatch.Frequency);
93 public double?[,]
Milliseconds => this.GetScaledTicks(1000.0 / Stopwatch.Frequency);
99 public double?[,]
Microseconds => this.GetScaledTicks(1000000.0 / Stopwatch.Frequency);
101 private double?[,] GetScaledTicks(
double Scale)
103 lock (this.syncObject)
105 return this.GetScaledTicksLocked(Scale);
109 private double?[,] GetScaledTicksLocked(
double Scale)
111 double?[,] Result =
new double?[this.tests.Count, this.complexities.Count];
115 foreach (
string Name
in this.tests.Keys)
118 foreach (
long Complexity
in this.complexities.Keys)
120 if (this.ticks.TryGetValue(Name, out Dictionary<long, long>
Complexities) &&
123 Result[i, j] =
Ticks * Scale;
161 private string GetResultScript(
double Scale)
163 StringBuilder sb =
new StringBuilder();
165 long[] ComplexitiesN;
170 lock (this.syncObject)
172 Names = this.GetTestsLocked();
173 ComplexitiesN = this.GetComplexitiesLocked();
174 Values = this.GetScaledTicksLocked(Scale);
178 N = ComplexitiesN.Length;
180 sb.Append(
"[[\"N\\\\Test\"");
181 foreach (
string Name
in Names)
184 sb.Append(Name.Replace(
"\"",
"\\\""));
189 for (j = 0; j < N; j++)
191 sb.Append(
",\r\n [");
192 sb.Append(ComplexitiesN[j].ToString());
194 for (i = 0; i < c; i++)
200 sb.Append(d.Value.ToString(CultureInfo.InvariantCulture));
210 return sb.ToString();
222 GC.GetTotalMemory(
true);
224 lock (this.syncObject)
226 if (!this.tests.ContainsKey(Name))
227 this.tests[Name] =
true;
229 if (!this.complexities.ContainsKey(Complexity))
230 this.complexities[Complexity] =
true;
233 return new Benchmarking(
this, Name, Complexity, 0, this.watch.ElapsedTicks);
243 public void Stop(
string Name,
long N,
long M,
long StartTicks)
245 long ElapsedTicks = this.watch.ElapsedTicks - StartTicks;
247 lock (this.syncObject)
249 if (!this.ticks.TryGetValue(Name, out Dictionary<long, long>
Complexities))
266 lock (this.syncObject)
268 this.ticks.Remove(Name);
269 return this.tests.Remove(Name);
280 lock (this.syncObject)
282 foreach (Dictionary<long, long>
Complexities in this.ticks.Values)
285 return this.complexities.Remove(N);
Class that keeps track of benchmarking results by name, complexity and timing.
bool Remove(string Name)
Removes a benchmark.
string GetResultScriptTicks()
Gets benchmarking result in ticks, as script.
void Stop(string Name, long N, long M, long StartTicks)
Stops a benchmark.
void Dispose()
Disposes of the object.
bool Remove(long N)
Removes a complexity.
string GetResultScriptMicroseconds()
Gets benchmarking result in microseconds, as script.
long[] Complexities
Registered complexities.
double?[,] Seconds
Benchmarking results, in seconds, Test names of the first index, complexities in the second.
double?[,] Minutes
Benchmarking results, in minutes, Test names of the first index, complexities in the second.
string GetResultScriptSeconds()
Gets benchmarking result in seconds, as script.
string[] Tests
Registered tests.
double?[,] Microseconds
Benchmarking results, in microseconds, Test names of the first index, complexities in the second.
Benchmarking Start(string Name, long Complexity)
Starts a benchmark.
double?[,] Ticks
Benchmarking results, in ticks. Test names of the first index, complexities in the second.
string GetResultScriptMilliseconds()
Gets benchmarking result in milliseconds, as script.
double?[,] Milliseconds
Benchmarking results, in milliseconds, Test names of the first index, complexities in the second.
Benchmarker2D()
Class that keeps track of benchmarking results by name, complexity and timing.
Class that keeps track of benchmarking results and timing.
Class that keeps track of benchmarking results and timing.