Skip to content

Commit 935f262

Browse files
authored
Merge pull request #32 from danleh/performance-mark-measure
Add performance.mark/measure to runner
2 parents 86e3148 + b425021 commit 935f262

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
@@ -555,14 +555,23 @@ class Benchmark {
555555
return `
556556
let __benchmark = new Benchmark(${this.iterations});
557557
let results = [];
558+
let benchmarkName = "${this.name}";
559+
558560
for (let i = 0; i < ${this.iterations}; i++) {
559561
if (__benchmark.prepareForNextIteration)
560562
__benchmark.prepareForNextIteration();
561563
562564
${this.preIterationCode}
565+
566+
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
567+
const iterationStartMark = performance.mark(iterationMarkLabel);
568+
563569
let start = performance.now();
564570
__benchmark.runIteration();
565571
let end = performance.now();
572+
573+
performanceMeasure(iterationMarkLabel, iterationStartMark);
574+
566575
${this.postIterationCode}
567576
568577
results.push(Math.max(1, end - start));
@@ -623,7 +632,24 @@ class Benchmark {
623632
assert(false, "Should not reach here in CLI");
624633
};
625634

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

628654
if (!!this.plan.deterministicRandom) {
629655
addScript(`
@@ -687,7 +713,7 @@ class Benchmark {
687713
}
688714
addScript(this.runnerCode);
689715

690-
this.startTime = new Date();
716+
this.startTime = performance.now();
691717

692718
if (RAMification)
693719
resetMemoryPeak();
@@ -702,7 +728,7 @@ class Benchmark {
702728
}
703729
const results = await promise;
704730

705-
this.endTime = new Date();
731+
this.endTime = performance.now();
706732

707733
if (RAMification) {
708734
const memoryFootprint = MemoryFootprint();
@@ -1007,12 +1033,22 @@ class AsyncBenchmark extends DefaultBenchmark {
10071033
async function doRun() {
10081034
let __benchmark = new Benchmark();
10091035
let results = [];
1036+
let benchmarkName = "${this.name}";
1037+
10101038
for (let i = 0; i < ${this.iterations}; i++) {
10111039
${this.preIterationCode}
1040+
1041+
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
1042+
const iterationStartMark = performance.mark(iterationMarkLabel);
1043+
10121044
let start = performance.now();
10131045
await __benchmark.runIteration();
10141046
let end = performance.now();
1047+
1048+
performanceMeasure(iterationMarkLabel, iterationStartMark);
1049+
10151050
${this.postIterationCode}
1051+
10161052
results.push(Math.max(1, end - start));
10171053
}
10181054
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)