3using System.Diagnostics;
4using System.Globalization;
14 private readonly SortedDictionary<string, long> tests =
new SortedDictionary<string, long>();
15 private readonly
object syncObject =
new object();
16 private readonly Stopwatch watch;
23 this.watch =
new Stopwatch();
34 lock (this.syncObject)
36 return this.GetTestsLocked();
41 private string[] GetTestsLocked()
43 string[] Result =
new string[this.tests.Count];
44 this.tests.Keys.CopyTo(Result, 0);
52 public double?[]
Ticks => this.GetScaledTicks(1);
58 public double?[]
Minutes => this.GetScaledTicks(1.0 / (Stopwatch.Frequency * 60.0));
64 public double?[]
Seconds => this.GetScaledTicks(1.0 / Stopwatch.Frequency);
70 public double?[]
Milliseconds => this.GetScaledTicks(1000.0 / Stopwatch.Frequency);
76 public double?[]
Microseconds => this.GetScaledTicks(1000000.0 / Stopwatch.Frequency);
78 private double?[] GetScaledTicks(
double Scale)
80 lock (this.syncObject)
82 return this.GetScaledTicksLocked(Scale);
86 private double?[] GetScaledTicksLocked(
double Scale)
88 double?[] Result =
new double?[this.tests.Count];
92 foreach (
string Name
in this.tests.Keys)
94 if (this.tests.TryGetValue(Name, out
long Ticks))
95 Result[i] =
Ticks * Scale;
129 private string GetResultScript(
double Scale)
131 StringBuilder sb =
new StringBuilder();
137 lock (this.syncObject)
139 Names = this.GetTestsLocked();
140 Values = this.GetScaledTicksLocked(Scale);
147 for (i = 0; i < c; i++)
152 sb.Append(Names[i].Replace(
"\"",
"\\\""));
157 sb.Append(d.Value.ToString(CultureInfo.InvariantCulture));
166 return sb.ToString();
177 GC.GetTotalMemory(
true);
179 lock (this.syncObject)
181 if (!this.tests.ContainsKey(Name))
182 this.tests[Name] = 0;
185 return new Benchmarking(
this, Name, 0, 0, this.watch.ElapsedTicks);
195 public void Stop(
string Name,
long N,
long M,
long StartTicks)
197 long ElapsedTicks = this.watch.ElapsedTicks - StartTicks;
199 lock (this.syncObject)
201 this.tests[Name] = ElapsedTicks;
212 lock (this.syncObject)
214 return this.tests.Remove(Name);
Class that keeps track of benchmarking results by name and timing.
double?[] Seconds
Benchmarking results, in seconds, Test names of the first index, complexities in the second.
string[] Tests
Registered tests.
string GetResultScriptTicks()
Gets benchmarking result in ticks, as script.
string GetResultScriptMilliseconds()
Gets benchmarking result in milliseconds, as script.
Benchmarker1D()
Class that keeps track of benchmarking results and timing.
Benchmarking Start(string Name)
Starts a benchmark.
string GetResultScriptSeconds()
Gets benchmarking result in seconds, as script.
double?[] Minutes
Benchmarking results, in minutes, Test names of the first index, complexities in the second.
bool Remove(string Name)
Removes a benchmark.
string GetResultScriptMicroseconds()
Gets benchmarking result in microseconds, as script.
double?[] Milliseconds
Benchmarking results, in milliseconds, Test names of the first index, complexities in the second.
double?[] Ticks
Benchmarking results, in ticks. Test names of the first index, complexities in the second.
void Dispose()
Disposes of the object.
void Stop(string Name, long N, long M, long StartTicks)
Stops a benchmark.
double?[] Microseconds
Benchmarking results, in microseconds, Test names of the first index, complexities in the second.
Class that keeps track of benchmarking results and timing.
Class that keeps track of benchmarking results and timing.