From 9dff10ad77e99af6decc859406b28f65fd1f4454 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 29 Jul 2025 19:31:16 +0200 Subject: [PATCH 1/6] add cli help --- cli.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++-- shell-config.js | 5 ----- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index 1e11c5de..06353552 100644 --- a/cli.js +++ b/cli.js @@ -24,7 +24,43 @@ */ 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 (cliArgs.length) + globalThis.testList = cliArgs; + async function runJetStream() { try { @@ -36,4 +72,21 @@ 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 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; From 6c250b050405267c5a9fe3d95bc2e547fbf01d92 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 29 Jul 2025 19:35:07 +0200 Subject: [PATCH 2/6] update help --- cli.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cli.js b/cli.js index 06353552..4fcedc16 100644 --- a/cli.js +++ b/cli.js @@ -76,17 +76,25 @@ async function 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 tests:") - const benchmarkNames = BENCHMARKS.map(b => b.name).sort() + 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) + console.log(" ", benchmark); } else { runJetStream(); } From 367030e419d77e0e63ff5fdd0b923fdfcfd78fd6 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 29 Jul 2025 19:38:38 +0200 Subject: [PATCH 3/6] add semicolons --- JetStreamDriver.js | 4 ++-- cli.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 60565e77..132e2de8 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -48,8 +48,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) { diff --git a/cli.js b/cli.js index 4fcedc16..78ff1f57 100644 --- a/cli.js +++ b/cli.js @@ -25,7 +25,7 @@ load("./shell-config.js") -const cliFlags = {__proto__:null}; +const cliFlags = { __proto__: null }; const cliArgs = []; if (globalThis.arguments?.length) { for (const argument of globalThis.arguments) @@ -38,19 +38,19 @@ if (globalThis.arguments?.length) { function getIntFlag(flags, flag) { if (!(flag in flags)) - return undefined + 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 + throw new Error(`Expected positive value for ${flag}, but got ${rawValue}`); + return value; } if ("--iteration-count" in cliFlags) - globalThis.testIterationCount = getIntFlag(cliFlags, "--iteration-count") + globalThis.testIterationCount = getIntFlag(cliFlags, "--iteration-count"); if ("--worst-case-count" in cliFlags) - globalThis.testWorstCaseCount = getIntFlag(cliFlags, "--worst-case-count") + globalThis.testWorstCaseCount = getIntFlag(cliFlags, "--worst-case-count"); if ("--dump-json-results" in cliFlags) globalThis.dumpJSONResults = true; From c08704f4353649f9a25cb1baa0fe2e57e65c00ea Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Wed, 30 Jul 2025 15:51:34 +0200 Subject: [PATCH 4/6] address comments --- cli.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli.js b/cli.js index 78ff1f57..d62cd4c8 100644 --- a/cli.js +++ b/cli.js @@ -46,17 +46,16 @@ function getIntFlag(flags, flag) { 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"); +globalThis.testIterationCount = getIntFlag(cliFlags, "--iteration-count"); +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; @@ -81,7 +80,7 @@ if ("--help" in cliFlags) { 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(" --worst-case-count: Set the default worst-case count"); console.log(" --dump-json-results: Print summary json to the console."); console.log(""); From 0ed27d2a638f4d7824e38dc7f38231ef1aca0b5f Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Wed, 30 Jul 2025 16:34:48 +0200 Subject: [PATCH 5/6] make flag override more consistent --- JetStreamDriver.js | 9 ++++++--- cli.js | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 132e2de8..5616cf3b 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -61,15 +61,18 @@ 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 (urlParameters.has("startDelay")) + globalThis.startDelay = getIntParam(urlParameters, "startDelay"); if (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. diff --git a/cli.js b/cli.js index d62cd4c8..612a7b68 100644 --- a/cli.js +++ b/cli.js @@ -46,17 +46,16 @@ function getIntFlag(flags, flag) { return value; } -globalThis.testIterationCount = getIntFlag(cliFlags, "--iteration-count"); -globalThis.testWorstCaseCount = getIntFlag(cliFlags, "--worst-case-count"); - +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; From 83c5dbfdc9f89899f8547169d383c51e283151cd Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Wed, 30 Jul 2025 16:40:31 +0200 Subject: [PATCH 6/6] fix shouldReport --- JetStreamDriver.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 5616cf3b..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)) @@ -60,10 +59,11 @@ function getTestListParam(urlParams, key) { if (typeof(URLSearchParams) !== "undefined") { const urlParameters = new URLSearchParams(window.location.search); - shouldReport = urlParameters.has('report') && urlParameters.get('report').toLowerCase() == 'true'; + if (urlParameters.has("report")) + globalThis.shouldReport = urlParameters.get("report").toLowerCase() == "true"; if (urlParameters.has("startDelay")) globalThis.startDelay = getIntParam(urlParameters, "startDelay"); - if (shouldReport && !globalThis.startDelay) + if (globalThis.shouldReport && !globalThis.startDelay) globalThis.startDelay = 4000; if (urlParameters.has("tag")) globalThis.testList = getTestListParam(urlParameters, "tag"); @@ -601,7 +601,7 @@ class Driver { if (!isInBrowser) return; - if (!shouldReport) + if (!globalThis.shouldReport) return; const content = this.resultsJSON();