| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | 2 |
| 3 library BenchmarkBase; | 3 library BenchmarkBase; |
| 4 | 4 |
| 5 class Expect { | 5 class Expect { |
| 6 static void equals(var expected, var actual) { | 6 static void equals(var expected, var actual) { |
| 7 if (expected != actual) { | 7 if (expected != actual) { |
| 8 throw "Values not equal: $expected vs $actual"; | 8 throw "Values not equal: $expected vs $actual"; |
| 9 } | 9 } |
| 10 } | 10 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // Exercices the benchmark. By default invokes [run] 10 times. | 41 // Exercices the benchmark. By default invokes [run] 10 times. |
| 42 void exercise() { | 42 void exercise() { |
| 43 for (int i = 0; i < 10; i++) { | 43 for (int i = 0; i < 10; i++) { |
| 44 run(); | 44 run(); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Not measured setup code executed prior to the benchmark runs. | 48 // Not measured setup code executed prior to the benchmark runs. |
| 49 void setup() {} | 49 void setup() {} |
| 50 | 50 |
| 51 // Not measures teardown code executed after the benchark runs. | 51 // Not measures teardown code executed after the benchmark runs. |
| 52 void teardown() {} | 52 void teardown() {} |
| 53 | 53 |
| 54 // Measures the score for this benchmark by executing it repeately until | 54 // Measures the score for this benchmark by executing it repeately until |
| 55 // time minimum has been reached. | 55 // time minimum has been reached. |
| 56 static double measureFor(Function f, int timeMinimum) { | 56 static double measureFor(Function f, int timeMinimum) { |
| 57 int time = 0; | 57 int time = 0; |
| 58 int iter = 0; | 58 int iter = 0; |
| 59 Stopwatch watch = new Stopwatch(); | 59 Stopwatch watch = new Stopwatch(); |
| 60 watch.start(); | 60 watch.start(); |
| 61 int elapsed = 0; | 61 int elapsed = 0; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 }, 2000); | 80 }, 2000); |
| 81 teardown(); | 81 teardown(); |
| 82 return result; | 82 return result; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void report() { | 85 void report() { |
| 86 double score = measure(); | 86 double score = measure(); |
| 87 print("$name(RunTime): $score us."); | 87 print("$name(RunTime): $score us."); |
| 88 } | 88 } |
| 89 } | 89 } |
| OLD | NEW |