diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 60565e77..ec0736a0 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -39,8 +39,7 @@ globalThis.testWorstCaseCountMap ??= new Map(); globalThis.dumpJSONResults ??= false; globalThis.testList ??= undefined; globalThis.startDelay ??= undefined; - -let shouldReport = false; +globalThis.shouldReport ??= false; function getIntParam(urlParams, key) { if (!urlParams.has(key)) @@ -48,8 +47,8 @@ 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 + throw new Error(`Expected positive value for ${key}, but got ${rawValue}`); + return value; } function getTestListParam(urlParams, key) { @@ -60,16 +59,20 @@ function getTestListParam(urlParams, key) { if (typeof(URLSearchParams) !== "undefined") { const urlParameters = new URLSearchParams(window.location.search); - shouldReport = urlParameters.has('report') && urlParameters.get('report').toLowerCase() == 'true'; - globalThis.startDelay = getIntParam(urlParameters, "startDelay"); - if (shouldReport && !globalThis.startDelay) + 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"); - globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount"); - globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount"); + if (urlParameters.has("iterationCount")) + globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount"); + if (urlParameters.has("worstCaseCount")) + globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount"); } // Used for the promise representing the current benchmark run. @@ -598,7 +601,7 @@ class Driver { if (!isInBrowser) return; - if (!shouldReport) + if (!globalThis.shouldReport) return; const content = this.resultsJSON(); diff --git a/cli.js b/cli.js index 1e11c5de..612a7b68 100644 --- a/cli.js +++ b/cli.js @@ -24,7 +24,41 @@ */ load("./shell-config.js") -load("./JetStreamDriver.js"); + +const cliFlags = { __proto__: null }; +const cliArgs = []; +if (globalThis.arguments?.length) { + for (const argument of globalThis.arguments) + if (argument.startsWith("--")) { + const parts = argument.split("="); + cliFlags[parts[0].toLowerCase()] = parts.slice(1).join("="); + } else + cliArgs.push(argument); +} + +function getIntFlag(flags, flag) { + if (!(flag in flags)) + return undefined; + const rawValue = flags[flag]; + const value = parseInt(rawValue); + if (value <= 0) + throw new Error(`Expected positive value for ${flag}, but got ${rawValue}`); + return value; +} + +if ("--iteration-count" in cliFlags) + globalThis.testIterationCount = getIntFlag(cliFlags, "--iteration-count"); +if ("--worst-case-count" in cliFlags) + globalThis.testWorstCaseCount = getIntFlag(cliFlags, "--worst-case-count"); +if ("--dump-json-results" in cliFlags) + globalThis.dumpJSONResults = true; +if (typeof runMode !== "undefined" && runMode == "RAMification") + globalThis.RAMification = true; +if ("--ramification" in cliFlags) + globalThis.RAMification = true; +if (cliArgs.length) + globalThis.testList = cliArgs; + async function runJetStream() { try { @@ -36,4 +70,29 @@ async function runJetStream() { throw e; } } -runJetStream(); + +load("./JetStreamDriver.js"); + +if ("--help" in cliFlags) { + console.log("JetStream Driver Help"); + console.log(""); + + console.log("Options:"); + console.log(" --iteration-count: Set the default iteration count."); + console.log(" --worst-case-count: Set the default worst-case count"); + console.log(" --dump-json-results: Print summary json to the console."); + console.log(""); + + console.log("Available tags:"); + const tagNames = Array.from(benchmarksByTag.keys()).sort(); + for (const tagName of tagNames) + console.log(" ", tagName); + console.log(""); + + console.log("Available tests:"); + const benchmarkNames = BENCHMARKS.map(b => b.name).sort(); + for (const benchmark of benchmarkNames) + console.log(" ", benchmark); +} else { + runJetStream(); +} diff --git a/shell-config.js b/shell-config.js index c38f4437..405ddcd8 100644 --- a/shell-config.js +++ b/shell-config.js @@ -37,8 +37,3 @@ if (isSpiderMonkey) { globalThis.readFile = readRelativeToScript; globalThis.arguments = scriptArgs; } -if (globalThis.arguments?.length) - globalThis.testList = globalThis.arguments.slice(); - -if (typeof runMode !== "undefined" && runMode == "RAMification") - globalThis.RAMification = true;