4e7920c487
This changes the way we handle dynamic at runtime to be more correct and cleaner. We now simply emit dynamic as dynamic instead of as core.Object. There are now two ways to construct a function type: one can construct a fuzzy function type (the default), or a definite function type. The constructor for a fuzzy function type replaces all uses of dynamic with bottom. This function type is used for all type annotations. Definite function types do not replace dynamic with bottom. These only occur as the runtime type of actual functions, for which we really know the type. Because we now eagerly sort this out when we create the function type, the subtyping code doesn't need to deal with this. This allows some additional subtyping: closures which actually are typed to take dynamic would previously not have been allowed to be cast to something with a concrete argument type. Now this is allowed (see the change in runtime_tests.js for an example of this). This fixes #107. BUG= R=vsm@google.com Review URL: https://codereview.chromium.org/1195523002
96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
dart_library.library('BenchmarkBase', null, /* Imports */[
|
|
"dart_runtime/dart",
|
|
'dart/core'
|
|
], /* Lazy imports */[
|
|
], function(exports, dart, core) {
|
|
'use strict';
|
|
let dartx = dart.dartx;
|
|
class Expect extends core.Object {
|
|
static equals(expected, actual) {
|
|
if (!dart.equals(expected, actual)) {
|
|
throw `Values not equal: ${expected} vs ${actual}`;
|
|
}
|
|
}
|
|
static listEquals(expected, actual) {
|
|
if (expected[dartx.length] != actual[dartx.length]) {
|
|
throw `Lists have different lengths: ${expected[dartx.length]} vs ${actual[dartx.length]}`;
|
|
}
|
|
for (let i = 0; dart.notNull(i) < dart.notNull(actual[dartx.length]); i = dart.notNull(i) + 1) {
|
|
Expect.equals(expected[dartx.get](i), actual[dartx.get](i));
|
|
}
|
|
}
|
|
fail(message) {
|
|
throw message;
|
|
}
|
|
}
|
|
dart.setSignature(Expect, {
|
|
methods: () => ({fail: [dart.dynamic, [dart.dynamic]]}),
|
|
statics: () => ({
|
|
equals: [dart.void, [dart.dynamic, dart.dynamic]],
|
|
listEquals: [dart.void, [core.List, core.List]]
|
|
}),
|
|
names: ['equals', 'listEquals']
|
|
});
|
|
class BenchmarkBase extends core.Object {
|
|
BenchmarkBase(name) {
|
|
this.name = name;
|
|
}
|
|
run() {}
|
|
warmup() {
|
|
this.run();
|
|
}
|
|
exercise() {
|
|
for (let i = 0; dart.notNull(i) < 10; i = dart.notNull(i) + 1) {
|
|
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 (dart.notNull(elapsed) < dart.notNull(timeMinimum)) {
|
|
dart.dcall(f);
|
|
elapsed = watch.elapsedMilliseconds;
|
|
iter = dart.notNull(iter) + 1;
|
|
}
|
|
return 1000.0 * dart.notNull(elapsed) / dart.notNull(iter);
|
|
}
|
|
measure() {
|
|
this.setup();
|
|
BenchmarkBase.measureFor(dart.fn(() => {
|
|
this.warmup();
|
|
}), 100);
|
|
let result = BenchmarkBase.measureFor(dart.fn(() => {
|
|
this.exercise();
|
|
}), 2000);
|
|
this.teardown();
|
|
return result;
|
|
}
|
|
report() {
|
|
let score = this.measure();
|
|
core.print(`${this.name}(RunTime): ${score} us.`);
|
|
}
|
|
}
|
|
dart.setSignature(BenchmarkBase, {
|
|
constructors: () => ({BenchmarkBase: [BenchmarkBase, [core.String]]}),
|
|
methods: () => ({
|
|
run: [dart.void, []],
|
|
warmup: [dart.void, []],
|
|
exercise: [dart.void, []],
|
|
setup: [dart.void, []],
|
|
teardown: [dart.void, []],
|
|
measure: [core.double, []],
|
|
report: [dart.void, []]
|
|
}),
|
|
statics: () => ({measureFor: [core.double, [core.Function, core.int]]}),
|
|
names: ['measureFor']
|
|
});
|
|
// Exports:
|
|
exports.Expect = Expect;
|
|
exports.BenchmarkBase = BenchmarkBase;
|
|
});
|