From 30483728ca69fd0d300bbed9b9b2713ff0ed1543 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Thu, 14 Aug 2025 09:35:33 +0200 Subject: [PATCH 1/2] update --- JetStreamDriver.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index d1ef7964..c02cc83d 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -725,8 +725,8 @@ class Benchmark { } get runnerCode() { - return ` - let __benchmark = new Benchmark(${this.iterations}); + return `{ + let benchmark = new Benchmark(${this.iterations}); let results = []; let benchmarkName = "${this.name}"; @@ -737,7 +737,7 @@ class Benchmark { const iterationStartMark = performance.mark(iterationMarkLabel); let start = performance.now(); - __benchmark.runIteration(); + benchmark.runIteration(i); let end = performance.now(); performance.measure(iterationMarkLabel, iterationMarkLabel); @@ -746,8 +746,9 @@ class Benchmark { results.push(Math.max(1, end - start)); } - __benchmark.validate?.(${this.iterations}); - top.currentResolve(results);`; + benchmark.validate?.(${this.iterations}); + top.currentResolve(results); + };`; } processResults(results) { @@ -773,7 +774,7 @@ class Benchmark { get prerunCode() { return null; } get preIterationCode() { - let code = `__benchmark.prepareForNextIteration?.();`; + let code = `benchmark.prepareForNextIteration?.();`; if (this.plan.deterministicRandom) code += `Math.random.__resetSeed();`; @@ -1218,10 +1219,10 @@ class AsyncBenchmark extends DefaultBenchmark { get runnerCode() { return ` async function doRun() { - let __benchmark = new Benchmark(); - await __benchmark.init?.(); - let results = []; - let benchmarkName = "${this.name}"; + const benchmark = new Benchmark(${this.iterations}); + await benchmark.init?.(); + const results = []; + const benchmarkName = "${this.name}"; for (let i = 0; i < ${this.iterations}; i++) { ${this.preIterationCode} @@ -1229,9 +1230,9 @@ class AsyncBenchmark extends DefaultBenchmark { const iterationMarkLabel = benchmarkName + "-iteration-" + i; const iterationStartMark = performance.mark(iterationMarkLabel); - let start = performance.now(); - await __benchmark.runIteration(); - let end = performance.now(); + const start = performance.now(); + await benchmark.runIteration(i); + const end = performance.now(); performance.measure(iterationMarkLabel, iterationMarkLabel); @@ -1239,7 +1240,7 @@ class AsyncBenchmark extends DefaultBenchmark { results.push(Math.max(1, end - start)); } - __benchmark.validate?.(${this.iterations}); + benchmark.validate?.(${this.iterations}); top.currentResolve(results); } doRun().catch((error) => { top.currentReject(error); });` @@ -1301,16 +1302,16 @@ class WSLBenchmark extends Benchmark { } get runnerCode() { - return ` - let benchmark = new Benchmark(); + return `{ + const benchmark = new Benchmark(); const benchmarkName = "${this.name}"; - let results = []; + const results = []; { const markLabel = benchmarkName + "-stdlib"; const startMark = performance.mark(markLabel); - let start = performance.now(); + const start = performance.now(); benchmark.buildStdlib(); results.push(performance.now() - start); @@ -1321,7 +1322,7 @@ class WSLBenchmark extends Benchmark { const markLabel = benchmarkName + "-mainRun"; const startMark = performance.mark(markLabel); - let start = performance.now(); + const start = performance.now(); benchmark.run(); results.push(performance.now() - start); @@ -1329,7 +1330,7 @@ class WSLBenchmark extends Benchmark { } top.currentResolve(results); - `; + }`; } subScores() { From bf9a2b4e28048221b9498b3f52196ca4a3e313e4 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Thu, 14 Aug 2025 09:40:04 +0200 Subject: [PATCH 2/2] fewer vars --- JetStreamDriver.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index c02cc83d..0e1ffef2 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -726,9 +726,9 @@ class Benchmark { get runnerCode() { return `{ - let benchmark = new Benchmark(${this.iterations}); - let results = []; - let benchmarkName = "${this.name}"; + const benchmark = new Benchmark(${this.iterations}); + const results = []; + const benchmarkName = "${this.name}"; for (let i = 0; i < ${this.iterations}; i++) { ${this.preIterationCode} @@ -736,9 +736,9 @@ class Benchmark { const iterationMarkLabel = benchmarkName + "-iteration-" + i; const iterationStartMark = performance.mark(iterationMarkLabel); - let start = performance.now(); + const start = performance.now(); benchmark.runIteration(i); - let end = performance.now(); + const end = performance.now(); performance.measure(iterationMarkLabel, iterationMarkLabel); @@ -925,7 +925,7 @@ class Benchmark { updateCounter() { const counter = JetStream.counter; ++counter.loadedResources; - var statusElement = document.getElementById("status"); + const statusElement = document.getElementById("status"); statusElement.innerHTML = `Loading ${counter.loadedResources} of ${counter.totalResources} ...`; } @@ -1411,7 +1411,7 @@ class WasmLegacyBenchmark extends Benchmark { if (isInBrowser) { str += ` - var xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.open('GET', path, true); xhr.responseType = 'arraybuffer'; xhr.onload = function() {