Skip to content

Commit b425021

Browse files
committed
Add performance.mark/measure to runner
...which can help to profile only code which is actually measured, not the setup and driver. Also some drive-by fixes: Add sqlite3-wasm to `wasm-cli.js` runner and fix typo.
1 parent 707b7a8 commit b425021

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

JetStreamDriver.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,23 @@ class Benchmark {
551551
return `
552552
let __benchmark = new Benchmark(${this.iterations});
553553
let results = [];
554+
let benchmarkName = "${this.name}";
555+
554556
for (let i = 0; i < ${this.iterations}; i++) {
555557
if (__benchmark.prepareForNextIteration)
556558
__benchmark.prepareForNextIteration();
557559
558560
${this.preIterationCode}
561+
562+
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
563+
const iterationStartMark = performance.mark(iterationMarkLabel);
564+
559565
let start = performance.now();
560566
__benchmark.runIteration();
561567
let end = performance.now();
568+
569+
performanceMeasure(iterationMarkLabel, iterationStartMark);
570+
562571
${this.postIterationCode}
563572
564573
results.push(Math.max(1, end - start));
@@ -619,7 +628,24 @@ class Benchmark {
619628
assert(false, "Should not reach here in CLI");
620629
};
621630

622-
addScript(`const isInBrowser = ${isInBrowser};`);
631+
addScript(`
632+
const isInBrowser = ${isInBrowser};
633+
const isD8 = ${isD8};
634+
if (typeof performance.mark === 'undefined') {
635+
performance.mark = function() {};
636+
}
637+
if (typeof performance.measure === 'undefined') {
638+
performance.measure = function() {};
639+
}
640+
function performanceMeasure(name, mark) {
641+
// D8 does not implement the official web API.
642+
// Also the performance.mark polyfill returns an undefined mark.
643+
if (isD8 || typeof mark === "undefined")
644+
performance.measure(name, mark);
645+
else
646+
performance.measure(name, mark.name);
647+
}
648+
`);
623649

624650
if (!!this.plan.deterministicRandom) {
625651
addScript(`
@@ -683,7 +709,7 @@ class Benchmark {
683709
}
684710
addScript(this.runnerCode);
685711

686-
this.startTime = new Date();
712+
this.startTime = performance.now();
687713

688714
if (RAMification)
689715
resetMemoryPeak();
@@ -698,7 +724,7 @@ class Benchmark {
698724
}
699725
const results = await promise;
700726

701-
this.endTime = new Date();
727+
this.endTime = performance.now();
702728

703729
if (RAMification) {
704730
const memoryFootprint = MemoryFootprint();
@@ -997,12 +1023,22 @@ class AsyncBenchmark extends DefaultBenchmark {
9971023
async function doRun() {
9981024
let __benchmark = new Benchmark();
9991025
let results = [];
1026+
let benchmarkName = "${this.name}";
1027+
10001028
for (let i = 0; i < ${this.iterations}; i++) {
10011029
${this.preIterationCode}
1030+
1031+
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
1032+
const iterationStartMark = performance.mark(iterationMarkLabel);
1033+
10021034
let start = performance.now();
10031035
await __benchmark.runIteration();
10041036
let end = performance.now();
1037+
1038+
performanceMeasure(iterationMarkLabel, iterationStartMark);
1039+
10051040
${this.postIterationCode}
1041+
10061042
results.push(Math.max(1, end - start));
10071043
}
10081044
if (__benchmark.validate)

wasm-cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ testList = [
2929
"quicksort-wasm",
3030
"gcc-loops-wasm",
3131
"richards-wasm",
32+
"sqlite3-wasm",
3233
"tfjs-wasm",
3334
"tfjs-wasm-simd",
3435
"argon2-wasm",
3536
"argon2-wasm-simd",
3637
"8bitbench-wasm",
3738
];
3839

39-
// Re-use the full CLI runner, just with the subset of Wasm line items above.
40+
// Reuse the full CLI runner, just with the subset of Wasm line items above.
4041
load("./cli.js");

0 commit comments

Comments
 (0)