OLD | NEW |
1 var BenchmarkBase; | 1 var BenchmarkBase; |
2 (function (BenchmarkBase) { | 2 (function(BenchmarkBase) { |
3 'use strict'; | 3 'use strict'; |
4 class Expect extends dart.Object { | 4 class Expect extends dart.Object { |
5 static equals(expected, actual) { | 5 static equals(expected, actual) { |
6 if (!dart.equals(expected, actual)) { | 6 if (!dart.equals(expected, actual)) { |
7 throw `Values not equal: ${expected} vs ${actual}`; | 7 throw `Values not equal: ${expected} vs ${actual}`; |
8 } | 8 } |
9 } | 9 } |
10 static listEquals(expected, actual) { | 10 static listEquals(expected, actual) { |
11 if (expected.length !== actual.length) { | 11 if (expected.length !== actual.length) { |
12 throw `Lists have different lengths: ${expected.length} vs ${actual.leng
th}`; | 12 throw `Lists have different lengths: ${expected.length} vs ${actual.leng
th}`; |
13 } | 13 } |
14 for (let i = 0; i < actual.length; i++) { | 14 for (let i = 0; i < actual.length; i++) { |
15 equals(expected.get(i), actual.get(i)); | 15 equals(expected.get(i), actual.get(i)); |
16 } | 16 } |
17 } | 17 } |
18 fail(message) { | 18 fail(message) { |
19 throw message; | 19 throw message; |
20 } | 20 } |
21 } | 21 } |
22 | |
23 class BenchmarkBase extends dart.Object { | 22 class BenchmarkBase extends dart.Object { |
24 BenchmarkBase(name) { | 23 BenchmarkBase(name) { |
25 this.name = name; | 24 this.name = name; |
26 } | 25 } |
27 run() { | 26 run() {} |
28 } | |
29 warmup() { | 27 warmup() { |
30 this.run(); | 28 this.run(); |
31 } | 29 } |
32 exercise() { | 30 exercise() { |
33 for (let i = 0; i < 10; i++) { | 31 for (let i = 0; i < 10; i++) { |
34 this.run(); | 32 this.run(); |
35 } | 33 } |
36 } | 34 } |
37 setup() { | 35 setup() {} |
38 } | 36 teardown() {} |
39 teardown() { | |
40 } | |
41 static measureFor(f, timeMinimum) { | 37 static measureFor(f, timeMinimum) { |
42 let time = 0; | 38 let time = 0; |
43 let iter = 0; | 39 let iter = 0; |
44 let watch = new core.Stopwatch(); | 40 let watch = new core.Stopwatch(); |
45 watch.start(); | 41 watch.start(); |
46 let elapsed = 0; | 42 let elapsed = 0; |
47 while (elapsed < timeMinimum) { | 43 while (elapsed < timeMinimum) { |
48 dart.dinvokef(f); | 44 dart.dinvokef(f); |
49 elapsed = watch.elapsedMilliseconds; | 45 elapsed = watch.elapsedMilliseconds; |
50 iter++; | 46 iter++; |
51 } | 47 } |
52 return 1000.0 * elapsed / iter; | 48 return 1000.0 * elapsed / iter; |
53 } | 49 } |
54 measure() { | 50 measure() { |
55 this.setup(); | 51 this.setup(); |
56 measureFor((() => { | 52 measureFor((() => { |
57 this.warmup(); | 53 this.warmup(); |
58 }).bind(this), 100); | 54 }).bind(this), 100); |
59 let result = measureFor((() => { | 55 let result = measureFor((() => { |
60 this.exercise(); | 56 this.exercise(); |
61 }).bind(this), 2000); | 57 }).bind(this), 2000); |
62 this.teardown(); | 58 this.teardown(); |
63 return result; | 59 return result; |
64 } | 60 } |
65 report() { | 61 report() { |
66 let score = this.measure(); | 62 let score = this.measure(); |
67 core.print(`${this.name}(RunTime): ${score} us.`); | 63 core.print(`${this.name}(RunTime): ${score} us.`); |
68 } | 64 } |
69 } | 65 } |
70 | |
71 // Exports: | 66 // Exports: |
72 BenchmarkBase.Expect = Expect; | 67 BenchmarkBase.Expect = Expect; |
73 BenchmarkBase.BenchmarkBase = BenchmarkBase; | 68 BenchmarkBase.BenchmarkBase = BenchmarkBase; |
74 })(BenchmarkBase || (BenchmarkBase = {})); | 69 })(BenchmarkBase || (BenchmarkBase = {})); |
OLD | NEW |