Skip to content

Commit 5d0005e

Browse files
committed
Move prepareForNextIteration call from Benchmark's runnerCode to preIterationCode
This makes it easier for Benchmark subclasses to also call. This fixes a bug in #74 which caused inspector code load benchmarks to not set up properly ending the benchmark in 0ms. Also, use optional chaining for the call (and few other similar optional helpers).
1 parent df99e62 commit 5d0005e

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

JetStreamDriver.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,6 @@ class Benchmark {
650650
let benchmarkName = "${this.name}";
651651
652652
for (let i = 0; i < ${this.iterations}; i++) {
653-
if (__benchmark.prepareForNextIteration)
654-
__benchmark.prepareForNextIteration();
655-
656653
${this.preIterationCode}
657654
658655
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
@@ -668,8 +665,7 @@ class Benchmark {
668665
669666
results.push(Math.max(1, end - start));
670667
}
671-
if (__benchmark.validate)
672-
__benchmark.validate(${this.iterations});
668+
__benchmark.validate?.(${this.iterations});
673669
top.currentResolve(results);`;
674670
}
675671

@@ -684,7 +680,7 @@ class Benchmark {
684680
get prerunCode() { return null; }
685681

686682
get preIterationCode() {
687-
let code = "";
683+
let code = `__benchmark.prepareForNextIteration?.();`;
688684
if (this.plan.deterministicRandom)
689685
code += `Math.random.__resetSeed();`;
690686

@@ -1185,8 +1181,7 @@ class AsyncBenchmark extends DefaultBenchmark {
11851181
return `
11861182
async function doRun() {
11871183
let __benchmark = new Benchmark();
1188-
if (__benchmark.init)
1189-
await __benchmark.init();
1184+
await __benchmark.init?.();
11901185
let results = [];
11911186
let benchmarkName = "${this.name}";
11921187
@@ -1206,8 +1201,7 @@ class AsyncBenchmark extends DefaultBenchmark {
12061201
12071202
results.push(Math.max(1, end - start));
12081203
}
1209-
if (__benchmark.validate)
1210-
__benchmark.validate(${this.iterations});
1204+
__benchmark.validate?.(${this.iterations});
12111205
top.currentResolve(results);
12121206
}
12131207
doRun().catch((error) => { top.currentReject(error); });`

0 commit comments

Comments
 (0)