7c1ab1f04d
Adds an explicit "extends dart.Object", which we probably want for other reasons (e.g. toString, runtimeType, hashCode) Attempts to recover some readability by tweaking the name of the initialize functions. This closes #51, but we should open another tracking bug because there are concerning aspects to this workaround. R=sigmund@google.com, vsm@google.com Review URL: https://chromereviews.googleplex.com/150417015
75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
var BenchmarkBase;
|
|
(function (BenchmarkBase) {
|
|
'use strict';
|
|
class Expect extends dart.Object {
|
|
static equals(expected, actual) {
|
|
if (!dart.equals(expected, actual)) {
|
|
throw `Values not equal: ${expected} vs ${actual}`;
|
|
}
|
|
}
|
|
static listEquals(expected, actual) {
|
|
if (expected.length !== actual.length) {
|
|
throw `Lists have different lengths: ${expected.length} vs ${actual.length}`;
|
|
}
|
|
for (let i = 0; i < actual.length; i++) {
|
|
equals(expected.get(i), actual.get(i));
|
|
}
|
|
}
|
|
fail(message) {
|
|
throw message;
|
|
}
|
|
}
|
|
|
|
class BenchmarkBase extends dart.Object {
|
|
BenchmarkBase(name) {
|
|
this.name = name;
|
|
}
|
|
run() {
|
|
}
|
|
warmup() {
|
|
this.run();
|
|
}
|
|
exercise() {
|
|
for (let i = 0; i < 10; i++) {
|
|
this.run();
|
|
}
|
|
}
|
|
setup() {
|
|
}
|
|
teardown() {
|
|
}
|
|
static measureFor(f, timeMinimum) {
|
|
let time = 0;
|
|
let iter = 0;
|
|
let watch = new core.Stopwatch();
|
|
watch.start();
|
|
let elapsed = 0;
|
|
while (elapsed < timeMinimum) {
|
|
dart.dinvokef(f);
|
|
elapsed = watch.elapsedMilliseconds;
|
|
iter++;
|
|
}
|
|
return 1000.0 * elapsed / iter;
|
|
}
|
|
measure() {
|
|
this.setup();
|
|
measureFor((() => {
|
|
this.warmup();
|
|
}).bind(this), 100);
|
|
let result = measureFor((() => {
|
|
this.exercise();
|
|
}).bind(this), 2000);
|
|
this.teardown();
|
|
return result;
|
|
}
|
|
report() {
|
|
let score = this.measure();
|
|
core.print(`${this.name}(RunTime): ${score} us.`);
|
|
}
|
|
}
|
|
|
|
// Exports:
|
|
BenchmarkBase.Expect = Expect;
|
|
BenchmarkBase.BenchmarkBase = BenchmarkBase;
|
|
})(BenchmarkBase || (BenchmarkBase = {}));
|