Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Dart/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ function addTaskQueue(self) {
ms = Math.max(0, ms);
var id = timerIdCounter++;
// A callback can be scheduled at most once.
// (console.assert is only available on D8)
// if (isD8) console.assert(f.$timerId === undefined);
console.assert(f.$timerId === undefined);
f.$timerId = id;
timerIds[id] = f;
if (ms == 0 && !isNextTimerDue()) {
Expand Down
50 changes: 19 additions & 31 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,22 @@ if (isInBrowser) {
};
}

function assert(b, m = "") {
if (!b)
throw new Error(`Bad assertion: ${m}`);
}


function mean(values) {
assert(values instanceof Array);
console.assert(values instanceof Array);
let sum = 0;
for (let x of values)
sum += x;
return sum / values.length;
}

function geomeanScore(values) {
assert(values instanceof Array);
console.assert(values instanceof Array);
let product = 1;
for (let x of values)
product *= x;
const score = product ** (1 / values.length);
// Allow 0 for uninitialized subScores().
assert(score >= 0, `Got invalid score: ${score}`)
console.assert(score >= 0, `Got invalid score: ${score}`)
return score;
}

Expand Down Expand Up @@ -206,7 +200,7 @@ class ShellFileLoader {
// Cache / memoize previously read files, because some workloads
// share common code.
load(url) {
assert(!isInBrowser);
console.assert(!isInBrowser);
if (!globalThis.prefetchResources)
return `load("${url}");`

Expand All @@ -230,7 +224,7 @@ class Driver {
// Make benchmark list unique and sort it.
this.benchmarks = Array.from(new Set(benchmarks));
this.benchmarks.sort((a, b) => a.plan.name.toLowerCase() < b.plan.name.toLowerCase() ? 1 : -1);
assert(this.benchmarks.length, "No benchmarks selected");
console.assert(this.benchmarks.length, "No benchmarks selected");
// TODO: Cleanup / remove / merge `blobDataCache` and `loadCache` vs.
// the global `fileLoader` cache.
this.blobDataCache = { };
Expand Down Expand Up @@ -290,7 +284,7 @@ class Driver {
const allScores = [];
for (const benchmark of this.benchmarks) {
const score = benchmark.score;
assert(score > 0, `Invalid ${benchmark.name} score: ${score}`);
console.assert(score > 0, `Invalid ${benchmark.name} score: ${score}`);
allScores.push(score);
}

Expand All @@ -303,13 +297,13 @@ class Driver {
for (const benchmark of this.benchmarks) {
for (let [category, value] of Object.entries(benchmark.subScores())) {
const arr = categoryScores.get(category);
assert(value > 0, `Invalid ${benchmark.name} ${category} score: ${value}`);
console.assert(value > 0, `Invalid ${benchmark.name} ${category} score: ${value}`);
arr.push(value);
}
}

const totalScore = geomeanScore(allScores);
assert(totalScore > 0, `Invalid total score: ${totalScore}`);
console.assert(totalScore > 0, `Invalid total score: ${totalScore}`);

if (isInBrowser) {
const summaryElement = document.getElementById("result-summary");
Expand Down Expand Up @@ -628,13 +622,7 @@ class ShellScripts extends Scripts {
} else
globalObject = runString("");

globalObject.console = {
log: globalObject.print,
warn: (e) => { print("Warn: " + e); },
error: (e) => { print("Error: " + e); },
debug: (e) => { print("Debug: " + e); },
};

globalObject.console = console;
globalObject.self = globalObject;
globalObject.top = {
currentResolve,
Expand All @@ -653,7 +641,7 @@ class ShellScripts extends Scripts {
}

addWithURL(url) {
assert(false, "Should not reach here in CLI");
console.assert(false, "Should not reach here in CLI");
}
}

Expand Down Expand Up @@ -813,7 +801,7 @@ class Benchmark {
scripts.add(prerunCode);

if (!isInBrowser) {
assert(this.scripts && this.scripts.length === this.plan.files.length);
console.assert(this.scripts && this.scripts.length === this.plan.files.length);
for (const text of this.scripts)
scripts.add(text);
} else {
Expand Down Expand Up @@ -929,7 +917,7 @@ class Benchmark {
}

prefetchResourcesForBrowser() {
assert(isInBrowser);
console.assert(isInBrowser);

const promises = this.plan.files.map((file) => this.loadBlob("file", null, file).then((blobData) => {
if (!globalThis.allIsGood)
Expand Down Expand Up @@ -962,7 +950,7 @@ class Benchmark {
}

async retryPrefetchResource(type, prop, file) {
assert(isInBrowser);
console.assert(isInBrowser);

const counter = JetStream.counter;
const blobData = JetStream.blobDataCache[file];
Expand Down Expand Up @@ -998,7 +986,7 @@ class Benchmark {
}

async retryPrefetchResourcesForBrowser() {
assert(isInBrowser);
console.assert(isInBrowser);

const counter = JetStream.counter;
for (const resource of this.plan.files) {
Expand All @@ -1019,12 +1007,12 @@ class Benchmark {
}

prefetchResourcesForShell() {
assert(!isInBrowser);
console.assert(!isInBrowser);

assert(this.scripts === null, "This initialization should be called only once.");
console.assert(this.scripts === null, "This initialization should be called only once.");
this.scripts = this.plan.files.map(file => shellFileLoader.load(file));

assert(this.preloads === null, "This initialization should be called only once.");
console.assert(this.preloads === null, "This initialization should be called only once.");
this.preloads = Object.entries(this.plan.preload ?? {});
}

Expand Down Expand Up @@ -1137,7 +1125,7 @@ class DefaultBenchmark extends Benchmark {
this.averageTime = null;
this.averageScore = null;

assert(this.iterations > this.worstCaseCount);
console.assert(this.iterations > this.worstCaseCount);
}

processResults(results) {
Expand All @@ -1149,7 +1137,7 @@ class DefaultBenchmark extends Benchmark {
results = results.slice(1);
results.sort((a, b) => a < b ? 1 : -1);
for (let i = 0; i + 1 < results.length; ++i)
assert(results[i] >= results[i + 1]);
console.assert(results[i] >= results[i + 1]);

const worstCase = [];
for (let i = 0; i < this.worstCaseCount; ++i)
Expand Down
23 changes: 17 additions & 6 deletions shell-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@
*/

const isInBrowser = false;
console = {
log: globalThis?.console?.log ?? print,
error: globalThis?.console?.error ?? print,
warn: globalThis?.console?.warn ?? print,
}
if (typeof console == "undefined")
console = {};

console.debug ??= (...args) => console.log("Debug:", ...args);
console.log ??= (...args) => print(args.join(" "));
console.warn ??= (...args) => console.log("Warn:", ...args);
console.error ??= (...args) => console.log("Error:", ...args);
console.assert ??= (condition, message) => {
if (!condition)
throw new Error(`Assertion failed: ${message}`);
};
console.trace ??= () => {
const targetObject = {};
Error.captureStackTrace(targetObject);
console.log(targetObject.stack);
};

const isD8 = typeof Realm !== "undefined";
if (isD8)
Expand All @@ -43,4 +54,4 @@ if (typeof performance == "undefined")
performance = {};

performance.mark ??= function(){};
performance.measure ??= function(){};
performance.measure ??= function(){};
Loading