Mercurial > projects > dynamin
comparison dynamin/core/benchmark.d @ 104:5c8c1c2e12c0
Change from real to double.
double is not dependant on the platform, and it uses less space.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Fri, 06 Jul 2012 18:39:45 -0500 |
parents | 73060bc3f004 |
children | acdbb30fee7e |
comparison
equal
deleted
inserted
replaced
103:73060bc3f004 | 104:5c8c1c2e12c0 |
---|---|
16 | 16 |
17 /** | 17 /** |
18 * Returns: The average number of milliseconds one call of the specified | 18 * Returns: The average number of milliseconds one call of the specified |
19 * delegate took. | 19 * delegate took. |
20 */ | 20 */ |
21 real benchmark(int repetitions, void delegate() dg) { // use static opCall()? | 21 double benchmark(int repetitions, void delegate() dg) { // use static opCall()? |
22 long time = Environment.runningTime; | 22 long time = Environment.runningTime; |
23 for(int i = 0; i < repetitions; ++i) | 23 for(int i = 0; i < repetitions; ++i) |
24 dg(); | 24 dg(); |
25 return (Environment.runningTime-time)/cast(real)repetitions; | 25 return (Environment.runningTime-time)/cast(double)repetitions; |
26 } | 26 } |
27 real benchmark(void delegate() dg) { | 27 double benchmark(void delegate() dg) { |
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 real benchmarkAndWrite(string name, int repetitions, void delegate() dg) { | 33 double benchmarkAndWrite(string name, int repetitions, void delegate() dg) { |
34 real 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 real benchmarkAndWrite(string name, void delegate() dg) { | 38 double benchmarkAndWrite(string 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 |