Skip to content

Commit 6ff39ea

Browse files
committed
Use Modularize instead of wrapping emcc's output.
This seems to work pretty nicely and should be future proof.
1 parent cb53112 commit 6ff39ea

File tree

6 files changed

+160
-129
lines changed

6 files changed

+160
-129
lines changed

JetStreamDriver.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ globalThis.dumpJSONResults ??= false;
3636
globalThis.customTestList ??= [];
3737

3838
let shouldReport = false;
39+
let startDelay;
3940
if (typeof(URLSearchParams) !== "undefined") {
4041
const urlParameters = new URLSearchParams(window.location.search);
4142
shouldReport = urlParameters.has('report') && urlParameters.get('report').toLowerCase() == 'true';
43+
if (shouldReport)
44+
startDelay = 4000;
45+
if (urlParameters.has('startDelay'))
46+
startDelay = urlParameters.get('startDelay');
4247
if (urlParameters.has('test'))
4348
customTestList = urlParameters.getAll("test");
49+
4450
}
4551

4652
// Used for the promise representing the current benchmark run.
@@ -414,8 +420,8 @@ class Driver {
414420
await this.prefetchResourcesForBrowser();
415421
await this.fetchResources();
416422
this.prepareToRun();
417-
if (isInBrowser && shouldReport) {
418-
setTimeout(() => this.start(), 4000);
423+
if (isInBrowser && startDelay !== undefined) {
424+
setTimeout(() => this.start(), startDelay);
419425
}
420426
}
421427

@@ -991,6 +997,7 @@ class AsyncBenchmark extends DefaultBenchmark {
991997
await __benchmark.runIteration();
992998
let end = performance.now();
993999
${this.postIterationCode}
1000+
console.log("iteration i: " + (end - start));
9941001
results.push(Math.max(1, end - start));
9951002
}
9961003
if (__benchmark.validate)
@@ -1001,7 +1008,10 @@ class AsyncBenchmark extends DefaultBenchmark {
10011008
}
10021009
};
10031010

1004-
class WasmBenchmark extends AsyncBenchmark {
1011+
// Meant for wasm benchmarks that are directly compiled with an emcc script and not part of a larger project's build system.
1012+
// Requires the following flags to emcc `-s MODULARIZE=1 -s EXPORT_NAME=setupModule -s EXPORTED_FUNCTIONS=_runIteration`
1013+
// in addition to any other benchmark specific flags.
1014+
class WasmEMCCBenchmark extends AsyncBenchmark {
10051015
get prerunCode() {
10061016
let str = `
10071017
let verbose = true;
@@ -1019,11 +1029,6 @@ class WasmBenchmark extends AsyncBenchmark {
10191029
console.log('Intercepted print: ', ...args);
10201030
};
10211031
1022-
let instanceReady;
1023-
let instancePromise = new Promise((resolve) => {
1024-
instanceReady = resolve;
1025-
});
1026-
10271032
let Module = {
10281033
preRun: [],
10291034
postRun: [],
@@ -1081,6 +1086,17 @@ class WasmBenchmark extends AsyncBenchmark {
10811086
for (let i = 0; i < keys.length; ++i) {
10821087
str += `loadBlob("${keys[i]}", "${this.plan.preload[keys[i]]}", () => {\n`;
10831088
}
1089+
str += `
1090+
class Benchmark {
1091+
async runIteration() {
1092+
if (!Module["_runIteration"])
1093+
await setupModule(Module);
1094+
1095+
Module["_runIteration"]();
1096+
}
1097+
};
1098+
`
1099+
10841100
str += super.runnerCode;
10851101
for (let i = 0; i < keys.length; ++i) {
10861102
str += `})`;
@@ -1892,7 +1908,7 @@ const testPlans = [
18921908
preload: {
18931909
wasmBinary: "./wasm/TSF/tsf.wasm"
18941910
},
1895-
benchmarkClass: WasmBenchmark,
1911+
benchmarkClass: WasmEMCCBenchmark,
18961912
testGroup: WasmGroup
18971913
},
18981914
{

wasm/TSF/build.sh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euo pipefail
44

55
emcc \
6-
-o tsf.js -O2 -s WASM=1 -s TOTAL_MEMORY=52428800 -g1 --emit-symbol-map -s EXPORTED_FUNCTIONS=_main,_runIteration \
6+
-o tsf.js -O2 -s MODULARIZE=1 -s EXPORT_NAME=setupModule -s WASM=1 -s TOTAL_MEMORY=52428800 -g1 --emit-symbol-map -s EXPORTED_FUNCTIONS=_main,_runIteration \
77
-I. -DTSF_BUILD_SYSTEM=1 \
88
tsf_asprintf.c\
99
tsf_buffer.c\
@@ -56,23 +56,3 @@ emcc \
5656
tsf_ir_different.c\
5757
tsf_ir_speed.c
5858

59-
TEMPFILE=`mktemp /tmp/tsf.XXXXXX`
60-
61-
(echo 'function setup(Module) {'; cat tsf.js; echo '}
62-
63-
class Benchmark {
64-
async runIteration() {
65-
if (!Module["_main"]) {
66-
let runtimeInitializedCallback;
67-
let runtimeInitialized = new Promise((success) => runtimeInitializedCallback = success);
68-
Module.onRuntimeInitialized = function() {
69-
runtimeInitializedCallback();
70-
}
71-
setup(Module);
72-
await runtimeInitialized;
73-
}
74-
75-
Module["_runIteration"]();
76-
}
77-
}') > $TEMPFILE
78-
mv $TEMPFILE tsf.js

0 commit comments

Comments
 (0)