1c26c3e1a6
well, at least they don't generate blatantly illegal ES6 code now :) also fixes incorrect implicit this generation, dynamic get/index, and set/setindex R=vsm@google.com Review URL: https://chromereviews.googleplex.com/146497013
75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
var BenchmarkBase;
|
|
(function (BenchmarkBase) {
|
|
'use strict';
|
|
class Expect {
|
|
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 {
|
|
constructor(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) {
|
|
/* Unimplemented dynamic method call: f() */;
|
|
elapsed = watch.elapsedMilliseconds;
|
|
iter++;
|
|
}
|
|
return 1000.0 * elapsed / iter;
|
|
}
|
|
measure() {
|
|
this.setup();
|
|
measureFor(() => {
|
|
this.warmup();
|
|
}, 100);
|
|
let result = measureFor(() => {
|
|
this.exercise();
|
|
}, 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 = {}));
|