File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,14 +34,24 @@ function dumpFrame(vec) {
3434
3535class Benchmark {
3636 isInstantiated = false ;
37+ romBinary ;
38+
39+ async init ( ) {
40+ if ( isInBrowser ) {
41+ let response = await fetch ( romBinary ) ;
42+ this . romBinary = new Int8Array ( await response . arrayBuffer ( ) ) ;
43+ } else {
44+ this . romBinary = new Int8Array ( read ( romBinary , "binary" ) ) ;
45+ }
46+ }
3747
3848 async runIteration ( ) {
3949 if ( ! this . isInstantiated ) {
4050 await wasm_bindgen ( Module . wasmBinary ) ;
4151 this . isInstantiated = true ;
4252 }
4353
44- wasm_bindgen . loadRom ( Module . romBinary ) ;
54+ wasm_bindgen . loadRom ( this . romBinary ) ;
4555
4656 const frameCount = 2 * 60 ;
4757 for ( let i = 0 ; i < frameCount ; ++ i ) {
Original file line number Diff line number Diff line change @@ -266,19 +266,14 @@ class Benchmark {
266266 // is a map from module variable name (which will hold the resulting module
267267 // namespace object) to relative module URL, which is resolved in the
268268 // `preRunnerCode`, similar to this code here.
269- if ( isInBrowser ) {
270- // In browsers, relative imports don't work since we are not in a module.
271- // (`import.meta.url` is not defined.)
272- const pathname = location . pathname . match ( / ^ ( .* \/ ) (?: [ ^ . ] + (?: \. (?: [ ^ \/ ] + ) ) + ) ? $ / ) [ 1 ] ;
273- this . dart2wasmJsModule = await import ( location . origin + pathname + "./Dart/build/flute.dart2wasm.mjs" ) ;
274- } else {
269+
270+ try {
271+ this . dart2wasmJsModule = await import ( jsModule ) ;
272+ } catch {
275273 // In shells, relative imports require different paths, so try with and
276274 // without the "./" prefix (e.g., JSC requires it).
277- try {
278- this . dart2wasmJsModule = await import ( "Dart/build/flute.dart2wasm.mjs" ) ;
279- } catch {
280- this . dart2wasmJsModule = await import ( "./Dart/build/flute.dart2wasm.mjs" ) ;
281- }
275+ if ( ! isInBrowser )
276+ this . dart2wasmJsModule = await import ( jsModule . slice ( "./" . length ) )
282277 }
283278 }
284279
Original file line number Diff line number Diff line change @@ -1228,8 +1228,12 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
12281228 }
12291229 ` ;
12301230
1231- for ( let [ preloadKey , blobURLOrPath ] of this . preloads )
1232- str += `await getBinary("${ preloadKey } ", "${ blobURLOrPath } ");\n`
1231+ for ( let [ preloadKey , blobURLOrPath ] of this . preloads ) {
1232+ if ( preloadKey == "wasmBinary" ) {
1233+ str += `await getBinary("${ preloadKey } ", "${ blobURLOrPath } ");\n`
1234+ break ;
1235+ }
1236+ }
12331237
12341238 str += super . runnerCode ;
12351239
@@ -2078,7 +2082,8 @@ let BENCHMARKS = [
20782082 "./Dart/benchmark.js" ,
20792083 ] ,
20802084 preload : {
2081- wasmBinary : "./Dart/build/flute.dart2wasm.wasm"
2085+ jsModule : "./Dart/build/flute.dart2wasm.mjs" ,
2086+ wasmBinary : "./Dart/build/flute.dart2wasm.wasm" ,
20822087 } ,
20832088 iterations : 15 ,
20842089 worstCaseCount : 2 ,
You can’t perform that action at this time.
0 commit comments