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