Skip to content
Open
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
113 changes: 31 additions & 82 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,7 @@ const measureTotalTimeAsSubtest = false; // Once we move to preloading all resou
const defaultIterationCount = 120;
const defaultWorstCaseCount = 4;

globalThis.performance ??= Date;
globalThis.RAMification ??= false;
globalThis.testIterationCount ??= undefined;
globalThis.testIterationCountMap ??= new Map();
globalThis.testWorstCaseCount ??= undefined;
globalThis.testWorstCaseCountMap ??= new Map();
globalThis.dumpJSONResults ??= false;
globalThis.testList ??= undefined;
globalThis.startDelay ??= undefined;
globalThis.shouldReport ??= false;
globalThis.prefetchResources ??= true;

function getIntParam(urlParams, key) {
const rawValue = urlParams.get(key);
const value = parseInt(rawValue);
if (value <= 0)
throw new Error(`Expected positive value for ${key}, but got ${rawValue}`);
return value;
}

function getBoolParam(urlParams, key) {
const rawValue = urlParams.get(key).toLowerCase()
return !(rawValue === "false" || rawValue === "0")
}

function getTestListParam(urlParams, key) {
if (globalThis.testList?.length)
throw new Error(`Overriding previous testList=${globalThis.testList.join()} with ${key} url-parameter.`);
return urlParams.getAll(key);
}

if (typeof(URLSearchParams) !== "undefined") {
const urlParameters = new URLSearchParams(window.location.search);
if (urlParameters.has("report"))
globalThis.shouldReport = urlParameters.get("report").toLowerCase() == "true";
if (urlParameters.has("startDelay"))
globalThis.startDelay = getIntParam(urlParameters, "startDelay");
if (globalThis.shouldReport && !globalThis.startDelay)
globalThis.startDelay = 4000;
if (urlParameters.has("tag"))
globalThis.testList = getTestListParam(urlParameters, "tag");
if (urlParameters.has("test"))
globalThis.testList = getTestListParam(urlParameters, "test");
if (urlParameters.has("iterationCount"))
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
if (urlParameters.has("worstCaseCount"))
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
if (urlParameters.has("prefetchResources"))
globalThis.prefetchResources = getBoolParam(urlParameters, "prefetchResources");
}

if (!globalThis.prefetchResources)
if (!JetStreamParams.prefetchResources)
console.warn("Disabling resource prefetching!");

// Used for the promise representing the current benchmark run.
Expand Down Expand Up @@ -110,20 +59,20 @@ function displayCategoryScores() {
}

function getIterationCount(plan) {
if (testIterationCountMap.has(plan.name))
return testIterationCountMap.get(plan.name);
if (globalThis.testIterationCount)
return globalThis.testIterationCount;
if (JetStreamParams.testIterationCountMap.has(plan.name))
return JetStreamParams.testIterationCountMap.get(plan.name);
if (JetStreamParams.testIterationCount)
return JetStreamParams.testIterationCount;
if (plan.iterations)
return plan.iterations;
return defaultIterationCount;
}

function getWorstCaseCount(plan) {
if (testWorstCaseCountMap.has(plan.name))
return testWorstCaseCountMap.get(plan.name);
if (globalThis.testWorstCaseCount)
return globalThis.testWorstCaseCount;
if (JetStreamParams.testWorstCaseCountMap.has(plan.name))
return JetStreamParams.testWorstCaseCountMap.get(plan.name);
if (JetStreamParams.testWorstCaseCount)
return JetStreamParams.testWorstCaseCount;
if (plan.worstCaseCount)
return plan.worstCaseCount;
return defaultWorstCaseCount;
Expand Down Expand Up @@ -201,7 +150,7 @@ class ShellFileLoader {
// share common code.
load(url) {
console.assert(!isInBrowser);
if (!globalThis.prefetchResources)
if (!JetStreamParams.prefetchResources)
return `load("${url}");`

if (this.requests.has(url)) {
Expand Down Expand Up @@ -240,7 +189,7 @@ class Driver {
if (isInBrowser) {
statusElement = document.getElementById("status");
statusElement.innerHTML = `<label>Running...</label>`;
} else if (!dumpJSONResults)
} else if (!JetStreamParams.dumpJSONResults)
console.log("Starting JetStream3");

performance.mark("update-ui-start");
Expand All @@ -260,7 +209,7 @@ class Driver {
performance.mark("update-ui");
benchmark.updateUIAfterRun();

if (isInBrowser && globalThis.prefetchResources) {
if (isInBrowser && JetStreamParams.prefetchResources) {
const cache = JetStream.blobDataCache;
for (const file of benchmark.files) {
const blobData = cache[file];
Expand All @@ -276,7 +225,7 @@ class Driver {
if (measureTotalTimeAsSubtest) {
if (isInBrowser)
document.getElementById("benchmark-total-time-score").innerHTML = uiFriendlyNumber(totalTime);
else if (!dumpJSONResults)
else if (!JetStreamParams.dumpJSONResults)
console.log("Total time:", uiFriendlyNumber(totalTime));
allScores.push(totalTime);
}
Expand Down Expand Up @@ -314,7 +263,7 @@ class Driver {
if (showScoreDetails)
displayCategoryScores();
statusElement.innerHTML = "";
} else if (!dumpJSONResults) {
} else if (!JetStreamParams.dumpJSONResults) {
console.log("\n");
for (let [category, scores] of categoryScores)
console.log(`${category}: ${uiFriendlyScore(geomeanScore(scores))}`);
Expand Down Expand Up @@ -404,8 +353,8 @@ class Driver {
this.isReady = true;
if (isInBrowser) {
globalThis.dispatchEvent(new Event("JetStreamReady"));
if (typeof(globalThis.startDelay) !== "undefined") {
setTimeout(() => this.start(), globalThis.startDelay);
if (typeof(JetStreamParams.startDelay) !== "undefined") {
setTimeout(() => this.start(), JetStreamParams.startDelay);
}
}
}
Expand Down Expand Up @@ -510,7 +459,7 @@ class Driver {

dumpJSONResultsIfNeeded()
{
if (dumpJSONResults) {
if (JetStreamParams.dumpJSONResults) {
console.log("\n");
console.log(this.resultsJSON());
console.log("\n");
Expand All @@ -529,7 +478,7 @@ class Driver {
if (!isInBrowser)
return;

if (!globalThis.shouldReport)
if (!JetStreamParams.shouldReport)
return;

const content = this.resultsJSON();
Expand Down Expand Up @@ -798,17 +747,17 @@ class Benchmark {
if (this.plan.deterministicRandom)
code += `Math.random.__resetSeed();`;

if (globalThis.customPreIterationCode)
code += customPreIterationCode;
if (JetStreamParams.customPreIterationCode)
code += JetStreamParams.customPreIterationCode;

return code;
}

get postIterationCode() {
let code = "";

if (globalThis.customPostIterationCode)
code += customPostIterationCode;
if (JetStreamParams.customPostIterationCode)
code += JetStreamParams.customPostIterationCode;

return code;
}
Expand Down Expand Up @@ -842,7 +791,7 @@ class Benchmark {
} else {
const cache = JetStream.blobDataCache;
for (const file of this.plan.files) {
scripts.addWithURL(globalThis.prefetchResources ? cache[file].blobURL : file);
scripts.addWithURL(JetStreamParams.prefetchResources ? cache[file].blobURL : file);
}
}

Expand All @@ -856,7 +805,7 @@ class Benchmark {
performance.mark(this.name);
this.startTime = performance.now();

if (RAMification)
if (JetStreamParams.RAMification)
resetMemoryPeak();

let magicFrame;
Expand All @@ -876,7 +825,7 @@ class Benchmark {
this.endTime = performance.now();
performance.measure(this.name, this.name);

if (RAMification) {
if (JetStreamParams.RAMification) {
const memoryFootprint = MemoryFootprint();
this.currentFootprint = memoryFootprint.current;
this.peakFootprint = memoryFootprint.peak;
Expand All @@ -893,7 +842,7 @@ class Benchmark {

async doLoadBlob(resource) {
const blobData = JetStream.blobDataCache[resource];
if (!globalThis.prefetchResources) {
if (!JetStreamParams.prefetchResources) {
blobData.blobURL = resource;
return blobData;
}
Expand Down Expand Up @@ -1061,7 +1010,7 @@ class Benchmark {
}

updateUIBeforeRun() {
if (!dumpJSONResults)
if (!JetStreamParams.dumpJSONResults)
console.log(`Running ${this.name}:`);
if (isInBrowser)
this.updateUIBeforeRunInBrowser();
Expand All @@ -1080,7 +1029,7 @@ class Benchmark {
const scoreEntries = Object.entries(this.allScores());
if (isInBrowser)
this.updateUIAfterRunInBrowser(scoreEntries);
if (dumpJSONResults)
if (JetStreamParams.dumpJSONResults)
return;
this.updateConsoleAfterRun(scoreEntries);
}
Expand Down Expand Up @@ -1139,7 +1088,7 @@ class Benchmark {
name = legacyScoreNameMap[name];
console.log(` ${name}:`, uiFriendlyScore(value));
}
if (RAMification) {
if (JetStreamParams.RAMification) {
console.log(" Current Footprint:", uiFriendlyNumber(this.currentFootprint));
console.log(" Peak Footprint:", uiFriendlyNumber(this.peakFootprint));
}
Expand Down Expand Up @@ -2701,8 +2650,8 @@ const defaultDisabledTags = [];
if (!isInBrowser)
defaultDisabledTags.push("WorkerTests");

if (globalThis.testList?.length) {
benchmarks = processTestList(globalThis.testList);
if (JetStreamParams.testList.length) {
benchmarks = processTestList(JetStreamParams.testList);
} else {
benchmarks = findBenchmarksByTag("Default", defaultDisabledTags)
}
Expand Down
Loading
Loading