Mercurial > projects > dynamin
comparison dynamin/core/benchmark.d @ 106:acdbb30fee7e
Port to D2.
Most of the effort was dealing with immutable and const.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 17 Dec 2012 23:41:50 -0600 |
parents | 5c8c1c2e12c0 |
children |
comparison
equal
deleted
inserted
replaced
105:97997a544ac0 | 106:acdbb30fee7e |
---|---|
28 return benchmark(1, dg); | 28 return benchmark(1, dg); |
29 } | 29 } |
30 /** | 30 /** |
31 * name can be null | 31 * name can be null |
32 */ | 32 */ |
33 double benchmarkAndWrite(string name, int repetitions, void delegate() dg) { | 33 double benchmarkAndWrite(cstring name, int repetitions, void delegate() dg) { |
34 double time = benchmark(repetitions, dg); | 34 double time = benchmark(repetitions, dg); |
35 Stdout.format("{} took {:.2}ms.", name, time).newline; // TODO: verify :.2 | 35 Stdout.format("{} took {:.2}ms.", name, time).newline; // TODO: verify :.2 |
36 return time; | 36 return time; |
37 } | 37 } |
38 double benchmarkAndWrite(string name, void delegate() dg) { | 38 double benchmarkAndWrite(cstring name, void delegate() dg) { |
39 return benchmarkAndWrite(name, 1, dg); | 39 return benchmarkAndWrite(name, 1, dg); |
40 } | 40 } |
41 | 41 |
42 /** | 42 /** |
43 * As the constructor calls the Start() method, the only time one would need | 43 * As the constructor calls the start() method, the only time one would need |
44 * to is when reusing a Benchmark object. | 44 * to is when reusing a Benchmark object. |
45 */ | 45 */ |
46 class Benchmark { | 46 class Benchmark { |
47 long _startTime; | 47 long _startTime; |
48 this() { | 48 this() { |
52 _startTime = Environment.runningTime; | 52 _startTime = Environment.runningTime; |
53 } | 53 } |
54 long time() { | 54 long time() { |
55 return _startTime-Environment.runningTime; | 55 return _startTime-Environment.runningTime; |
56 } | 56 } |
57 void writeTime(string opName) { | 57 void writeTime(cstring opName) { |
58 if(opName is null) | 58 if(opName is null) |
59 opName = "Benchmark"; | 59 opName = "Benchmark"; |
60 Stdout.format("{} took {}ms.", opName, time).newline; | 60 Stdout.format("{} took {}ms.", opName, time).newline; |
61 } | 61 } |
62 | 62 |