@@ -36,11 +36,17 @@ globalThis.dumpJSONResults ??= false;
36
36
globalThis . customTestList ??= [ ] ;
37
37
38
38
let shouldReport = false ;
39
+ let startDelay ;
39
40
if ( typeof ( URLSearchParams ) !== "undefined" ) {
40
41
const urlParameters = new URLSearchParams ( window . location . search ) ;
41
42
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' ) ;
42
47
if ( urlParameters . has ( 'test' ) )
43
48
customTestList = urlParameters . getAll ( "test" ) ;
49
+
44
50
}
45
51
46
52
// Used for the promise representing the current benchmark run.
@@ -414,8 +420,8 @@ class Driver {
414
420
await this . prefetchResourcesForBrowser ( ) ;
415
421
await this . fetchResources ( ) ;
416
422
this . prepareToRun ( ) ;
417
- if ( isInBrowser && shouldReport ) {
418
- setTimeout ( ( ) => this . start ( ) , 4000 ) ;
423
+ if ( isInBrowser && startDelay !== undefined ) {
424
+ setTimeout ( ( ) => this . start ( ) , startDelay ) ;
419
425
}
420
426
}
421
427
@@ -991,6 +997,7 @@ class AsyncBenchmark extends DefaultBenchmark {
991
997
await __benchmark.runIteration();
992
998
let end = performance.now();
993
999
${ this . postIterationCode }
1000
+ console.log("iteration i: " + (end - start));
994
1001
results.push(Math.max(1, end - start));
995
1002
}
996
1003
if (__benchmark.validate)
@@ -1001,7 +1008,10 @@ class AsyncBenchmark extends DefaultBenchmark {
1001
1008
}
1002
1009
} ;
1003
1010
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 {
1005
1015
get prerunCode ( ) {
1006
1016
let str = `
1007
1017
let verbose = true;
@@ -1019,11 +1029,6 @@ class WasmBenchmark extends AsyncBenchmark {
1019
1029
console.log('Intercepted print: ', ...args);
1020
1030
};
1021
1031
1022
- let instanceReady;
1023
- let instancePromise = new Promise((resolve) => {
1024
- instanceReady = resolve;
1025
- });
1026
-
1027
1032
let Module = {
1028
1033
preRun: [],
1029
1034
postRun: [],
@@ -1081,6 +1086,17 @@ class WasmBenchmark extends AsyncBenchmark {
1081
1086
for ( let i = 0 ; i < keys . length ; ++ i ) {
1082
1087
str += `loadBlob("${ keys [ i ] } ", "${ this . plan . preload [ keys [ i ] ] } ", () => {\n` ;
1083
1088
}
1089
+ str += `
1090
+ class Benchmark {
1091
+ async runIteration() {
1092
+ if (!Module["_runIteration"])
1093
+ await setupModule(Module);
1094
+
1095
+ Module["_runIteration"]();
1096
+ }
1097
+ };
1098
+ `
1099
+
1084
1100
str += super . runnerCode ;
1085
1101
for ( let i = 0 ; i < keys . length ; ++ i ) {
1086
1102
str += `})` ;
@@ -1892,7 +1908,7 @@ const testPlans = [
1892
1908
preload : {
1893
1909
wasmBinary : "./wasm/TSF/tsf.wasm"
1894
1910
} ,
1895
- benchmarkClass : WasmBenchmark ,
1911
+ benchmarkClass : WasmEMCCBenchmark ,
1896
1912
testGroup : WasmGroup
1897
1913
} ,
1898
1914
{
0 commit comments