OLD | NEW |
1 define(['dart_sdk'], function(dart_sdk) { | 1 define(['dart_sdk'], function(dart_sdk) { |
2 'use strict'; | 2 'use strict'; |
3 const core = dart_sdk.core; | 3 const core = dart_sdk.core; |
4 const dart = dart_sdk.dart; | 4 const dart = dart_sdk.dart; |
5 const dartx = dart_sdk.dartx; | 5 const dartx = dart_sdk.dartx; |
6 const BenchmarkBase$ = Object.create(null); | 6 const BenchmarkBase$ = Object.create(null); |
7 let VoidToNull = () => (VoidToNull = dart.constFn(dart.fnType(core.Null, [])))
(); | 7 let VoidToNull = () => (VoidToNull = dart.constFn(dart.fnType(core.Null, [])))
(); |
8 BenchmarkBase$.Expect = class Expect extends core.Object { | 8 BenchmarkBase$.Expect = class Expect extends core.Object { |
9 static equals(expected, actual) { | 9 static equals(expected, actual) { |
10 if (!dart.equals(expected, actual)) { | 10 if (!dart.equals(expected, actual)) { |
11 dart.throw(dart.str`Values not equal: ${expected} vs ${actual}`); | 11 dart.throw(dart.str`Values not equal: ${expected} vs ${actual}`); |
12 } | 12 } |
13 } | 13 } |
14 static listEquals(expected, actual) { | 14 static listEquals(expected, actual) { |
15 if (expected[dartx.length] != actual[dartx.length]) { | 15 if (expected[dartx.length] != actual[dartx.length]) { |
16 dart.throw(dart.str`Lists have different lengths: ${expected[dartx.lengt
h]} vs ${actual[dartx.length]}`); | 16 dart.throw(dart.str`Lists have different lengths: ${expected[dartx.lengt
h]} vs ${actual[dartx.length]}`); |
17 } | 17 } |
18 for (let i = 0; i < dart.notNull(actual[dartx.length]); i++) { | 18 for (let i = 0; i < dart.notNull(actual[dartx.length]); i++) { |
19 BenchmarkBase$.Expect.equals(expected[dartx._get](i), actual[dartx._get]
(i)); | 19 BenchmarkBase$.Expect.equals(expected[dartx._get](i), actual[dartx._get]
(i)); |
20 } | 20 } |
21 } | 21 } |
22 fail(message) { | 22 fail(message) { |
23 dart.throw(message); | 23 dart.throw(message); |
24 } | 24 } |
25 }; | 25 }; |
| 26 (BenchmarkBase$.Expect.new = function() { |
| 27 }).prototype = BenchmarkBase$.Expect.prototype; |
26 dart.setSignature(BenchmarkBase$.Expect, { | 28 dart.setSignature(BenchmarkBase$.Expect, { |
27 methods: () => ({fail: dart.fnType(dart.dynamic, [dart.dynamic])}), | 29 methods: () => ({fail: dart.fnType(dart.dynamic, [dart.dynamic])}), |
28 statics: () => ({ | 30 statics: () => ({ |
29 equals: dart.fnType(dart.void, [dart.dynamic, dart.dynamic]), | 31 equals: dart.fnType(dart.void, [dart.dynamic, dart.dynamic]), |
30 listEquals: dart.fnType(dart.void, [core.List, core.List]) | 32 listEquals: dart.fnType(dart.void, [core.List, core.List]) |
31 }), | 33 }), |
32 names: ['equals', 'listEquals'] | 34 names: ['equals', 'listEquals'] |
33 }); | 35 }); |
34 BenchmarkBase$.BenchmarkBase = class BenchmarkBase extends core.Object { | 36 BenchmarkBase$.BenchmarkBase = class BenchmarkBase extends core.Object { |
35 get name() { | 37 get name() { |
36 return this[name$]; | 38 return this[name$]; |
37 } | 39 } |
38 set name(value) { | 40 set name(value) { |
39 super.name = value; | 41 super.name = value; |
40 } | 42 } |
41 new(name) { | |
42 this[name$] = name; | |
43 } | |
44 run() {} | 43 run() {} |
45 warmup() { | 44 warmup() { |
46 this.run(); | 45 this.run(); |
47 } | 46 } |
48 exercise() { | 47 exercise() { |
49 for (let i = 0; i < 10; i++) { | 48 for (let i = 0; i < 10; i++) { |
50 this.run(); | 49 this.run(); |
51 } | 50 } |
52 } | 51 } |
53 setup() {} | 52 setup() {} |
54 teardown() {} | 53 teardown() {} |
55 static measureFor(f, timeMinimum) { | 54 static measureFor(f, timeMinimum) { |
56 let time = 0; | 55 let time = 0; |
57 let iter = 0; | 56 let iter = 0; |
58 let watch = new core.Stopwatch(); | 57 let watch = new core.Stopwatch.new(); |
59 watch.start(); | 58 watch.start(); |
60 let elapsed = 0; | 59 let elapsed = 0; |
61 while (dart.notNull(elapsed) < dart.notNull(timeMinimum)) { | 60 while (dart.notNull(elapsed) < dart.notNull(timeMinimum)) { |
62 dart.dcall(f); | 61 dart.dcall(f); |
63 elapsed = watch.elapsedMilliseconds; | 62 elapsed = watch.elapsedMilliseconds; |
64 iter++; | 63 iter++; |
65 } | 64 } |
66 return 1000.0 * dart.notNull(elapsed) / iter; | 65 return 1000.0 * dart.notNull(elapsed) / iter; |
67 } | 66 } |
68 measure() { | 67 measure() { |
69 this.setup(); | 68 this.setup(); |
70 BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => { | 69 BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => { |
71 this.warmup(); | 70 this.warmup(); |
72 }, VoidToNull()), 100); | 71 }, VoidToNull()), 100); |
73 let result = BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => { | 72 let result = BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => { |
74 this.exercise(); | 73 this.exercise(); |
75 }, VoidToNull()), 2000); | 74 }, VoidToNull()), 2000); |
76 this.teardown(); | 75 this.teardown(); |
77 return result; | 76 return result; |
78 } | 77 } |
79 report() { | 78 report() { |
80 let score = this.measure(); | 79 let score = this.measure(); |
81 core.print(dart.str`${this.name}(RunTime): ${score} us.`); | 80 core.print(dart.str`${this.name}(RunTime): ${score} us.`); |
82 } | 81 } |
83 }; | 82 }; |
| 83 (BenchmarkBase$.BenchmarkBase.new = function(name) { |
| 84 this[name$] = name; |
| 85 }).prototype = BenchmarkBase$.BenchmarkBase.prototype; |
84 const name$ = Symbol("BenchmarkBase.name"); | 86 const name$ = Symbol("BenchmarkBase.name"); |
85 dart.setSignature(BenchmarkBase$.BenchmarkBase, { | 87 dart.setSignature(BenchmarkBase$.BenchmarkBase, { |
86 fields: () => ({name: dart.finalFieldType(core.String)}), | 88 fields: () => ({name: dart.finalFieldType(core.String)}), |
87 methods: () => ({ | 89 methods: () => ({ |
88 run: dart.fnType(dart.void, []), | 90 run: dart.fnType(dart.void, []), |
89 warmup: dart.fnType(dart.void, []), | 91 warmup: dart.fnType(dart.void, []), |
90 exercise: dart.fnType(dart.void, []), | 92 exercise: dart.fnType(dart.void, []), |
91 setup: dart.fnType(dart.void, []), | 93 setup: dart.fnType(dart.void, []), |
92 teardown: dart.fnType(dart.void, []), | 94 teardown: dart.fnType(dart.void, []), |
93 measure: dart.fnType(core.double, []), | 95 measure: dart.fnType(core.double, []), |
94 report: dart.fnType(dart.void, []) | 96 report: dart.fnType(dart.void, []) |
95 }), | 97 }), |
96 statics: () => ({measureFor: dart.fnType(core.double, [core.Function, core.i
nt])}), | 98 statics: () => ({measureFor: dart.fnType(core.double, [core.Function, core.i
nt])}), |
97 names: ['measureFor'] | 99 names: ['measureFor'] |
98 }); | 100 }); |
99 dart.trackLibraries("BenchmarkBase", { | 101 dart.trackLibraries("BenchmarkBase", { |
100 "BenchmarkBase.dart": BenchmarkBase$ | 102 "BenchmarkBase.dart": BenchmarkBase$ |
101 }, null); | 103 }, null); |
102 // Exports: | 104 // Exports: |
103 return { | 105 return { |
104 BenchmarkBase: BenchmarkBase$ | 106 BenchmarkBase: BenchmarkBase$ |
105 }; | 107 }; |
106 }); | 108 }); |
OLD | NEW |