@@ -115,7 +115,7 @@ if (isInBrowser) {
115115
116116function assert ( b , m = "" ) {
117117 if ( ! b )
118- throw new Error ( " Bad assertion: " + m ) ;
118+ throw new Error ( ` Bad assertion: ${ m } ` ) ;
119119}
120120
121121function firstID ( benchmark ) {
@@ -177,17 +177,8 @@ function uiFriendlyScore(num) {
177177 return uiFriendlyNumber ( num ) ;
178178}
179179
180- function uiFriendlyDuration ( time )
181- {
182- const minutes = time . getMinutes ( ) ;
183- const seconds = time . getSeconds ( ) ;
184- const milliSeconds = time . getMilliseconds ( ) ;
185- let result = "" + minutes + ":" ;
186-
187- result = result + ( seconds < 10 ? "0" : "" ) + seconds + "." ;
188- result = result + ( milliSeconds < 10 ? "00" : ( milliSeconds < 100 ? "0" : "" ) ) + milliSeconds ;
189-
190- return result ;
180+ function uiFriendlyDuration ( time ) {
181+ return `${ time . toFixed ( 3 ) } ms` ;
191182}
192183
193184const fileLoader = ( function ( ) {
@@ -321,7 +312,7 @@ class Driver {
321312
322313 if ( isInBrowser ) {
323314 summaryElement . classList . add ( 'done' ) ;
324- summaryElement . innerHTML = " <div class=\ "score\">" + uiFriendlyScore ( geomean ( allScores ) ) + " </div><label>Score</label>" ;
315+ summaryElement . innerHTML = ` <div class="score"> ${ uiFriendlyScore ( geomean ( allScores ) ) } </div><label>Score</label>` ;
325316 summaryElement . onclick = displayCategoryScores ;
326317 if ( showScoreDetails )
327318 displayCategoryScores ( ) ;
@@ -391,7 +382,7 @@ class Driver {
391382
392383 const magicFrame = magic . contentDocument . getElementById ( "magicframe" ) ;
393384 magicFrame . contentDocument . open ( ) ;
394- magicFrame . contentDocument . write ( " <!DOCTYPE html><head><title>benchmark payload</title></head><body>\n" + string + " </body></html>" ) ;
385+ magicFrame . contentDocument . write ( ` <!DOCTYPE html><head><title>benchmark payload</title></head><body>\n${ string } </body></html>` ) ;
395386
396387 return magicFrame ;
397388 }
@@ -403,11 +394,11 @@ class Driver {
403394 let text = "" ;
404395 let newBenchmarks = [ ] ;
405396 for ( const benchmark of this . benchmarks ) {
406- const id = JSON . stringify ( benchmark . constructor . scoreDescription ( ) ) ;
407- const description = JSON . parse ( id ) ;
397+ const description = Object . keys ( benchmark . subScores ( ) ) ;
398+ description . push ( "Score" ) ;
408399
409400 newBenchmarks . push ( benchmark ) ;
410- const scoreIds = benchmark . scoreIdentifiers ( )
401+ const scoreIds = benchmark . scoreIdentifiers ( ) ;
411402 const overallScoreId = scoreIds . pop ( ) ;
412403
413404 if ( isInBrowser ) {
@@ -650,9 +641,6 @@ class Benchmark {
650641 let benchmarkName = "${ this . name } ";
651642
652643 for (let i = 0; i < ${ this . iterations } ; i++) {
653- if (__benchmark.prepareForNextIteration)
654- __benchmark.prepareForNextIteration();
655-
656644 ${ this . preIterationCode }
657645
658646 const iterationMarkLabel = benchmarkName + "-iteration-" + i;
@@ -662,14 +650,13 @@ class Benchmark {
662650 __benchmark.runIteration();
663651 let end = performance.now();
664652
665- performanceMeasure (iterationMarkLabel, iterationStartMark );
653+ performance.measure (iterationMarkLabel, iterationMarkLabel );
666654
667655 ${ this . postIterationCode }
668656
669657 results.push(Math.max(1, end - start));
670658 }
671- if (__benchmark.validate)
672- __benchmark.validate(${ this . iterations } );
659+ __benchmark.validate?.(${ this . iterations } );
673660 top.currentResolve(results);` ;
674661 }
675662
@@ -684,7 +671,7 @@ class Benchmark {
684671 get prerunCode ( ) { return null ; }
685672
686673 get preIterationCode ( ) {
687- let code = "" ;
674+ let code = `__benchmark.prepareForNextIteration?.();` ;
688675 if ( this . plan . deterministicRandom )
689676 code += `Math.random.__resetSeed();` ;
690677
@@ -731,19 +718,11 @@ class Benchmark {
731718 const isInBrowser = ${ isInBrowser } ;
732719 const isD8 = ${ isD8 } ;
733720 if (typeof performance.mark === 'undefined') {
734- performance.mark = function() {};
721+ performance.mark = function(name ) { return { name } };
735722 }
736723 if (typeof performance.measure === 'undefined') {
737724 performance.measure = function() {};
738725 }
739- function performanceMeasure(name, mark) {
740- // D8 does not implement the official web API.
741- // Also the performance.mark polyfill returns an undefined mark.
742- if (isD8 || typeof mark === "undefined")
743- performance.measure(name, mark);
744- else
745- performance.measure(name, mark.name);
746- }
747726 ` ) ;
748727
749728 if ( ! ! this . plan . deterministicRandom ) {
@@ -1018,7 +997,6 @@ class Benchmark {
1018997 return this . _resourcesPromise ;
1019998 }
1020999
1021- static scoreDescription ( ) { throw new Error ( "Must be implemented by subclasses." ) ; }
10221000 scoreIdentifiers ( ) { throw new Error ( "Must be implemented by subclasses" ) ; }
10231001
10241002 updateUIBeforeRun ( ) {
@@ -1101,10 +1079,6 @@ class DefaultBenchmark extends Benchmark {
11011079 } ;
11021080 }
11031081
1104- static scoreDescription ( ) {
1105- return [ "First" , "Worst" , "Average" , "Score" ] ;
1106- }
1107-
11081082 scoreIdentifiers ( ) {
11091083 return [ firstID ( this ) , worst4ID ( this ) , avgID ( this ) , scoreID ( this ) ] ;
11101084 }
@@ -1131,7 +1105,7 @@ class DefaultBenchmark extends Benchmark {
11311105 console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
11321106 console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
11331107 }
1134- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1108+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
11351109 }
11361110}
11371111
@@ -1185,8 +1159,7 @@ class AsyncBenchmark extends DefaultBenchmark {
11851159 return `
11861160 async function doRun() {
11871161 let __benchmark = new Benchmark();
1188- if (__benchmark.init)
1189- await __benchmark.init();
1162+ await __benchmark.init?.();
11901163 let results = [];
11911164 let benchmarkName = "${ this . name } ";
11921165
@@ -1200,14 +1173,13 @@ class AsyncBenchmark extends DefaultBenchmark {
12001173 await __benchmark.runIteration();
12011174 let end = performance.now();
12021175
1203- performanceMeasure (iterationMarkLabel, iterationStartMark );
1176+ performance.measure (iterationMarkLabel, iterationMarkLabel );
12041177
12051178 ${ this . postIterationCode }
12061179
12071180 results.push(Math.max(1, end - start));
12081181 }
1209- if (__benchmark.validate)
1210- __benchmark.validate(${ this . iterations } );
1182+ __benchmark.validate?.(${ this . iterations } );
12111183 top.currentResolve(results);
12121184 }
12131185 doRun().catch((error) => { top.currentReject(error); });`
@@ -1300,7 +1272,7 @@ class WSLBenchmark extends Benchmark {
13001272 benchmark.buildStdlib();
13011273 results.push(performance.now() - start);
13021274
1303- performanceMeasure (markLabel, startMark );
1275+ performance.measure (markLabel, markLabel );
13041276 }
13051277
13061278 {
@@ -1311,7 +1283,7 @@ class WSLBenchmark extends Benchmark {
13111283 benchmark.run();
13121284 results.push(performance.now() - start);
13131285
1314- performanceMeasure (markLabel, startMark );
1286+ performance.measure (markLabel, markLabel );
13151287 }
13161288
13171289 top.currentResolve(results);
@@ -1325,10 +1297,6 @@ class WSLBenchmark extends Benchmark {
13251297 } ;
13261298 }
13271299
1328- static scoreDescription ( ) {
1329- return [ "Stdlib" , "MainRun" , "Score" ] ;
1330- }
1331-
13321300 scoreIdentifiers ( ) {
13331301 return [ "wsl-stdlib-score" , "wsl-tests-score" , "wsl-score-score" ] ;
13341302 }
@@ -1353,7 +1321,7 @@ class WSLBenchmark extends Benchmark {
13531321 console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
13541322 console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
13551323 }
1356- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1324+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
13571325 }
13581326} ;
13591327
@@ -1501,10 +1469,6 @@ class WasmLegacyBenchmark extends Benchmark {
15011469 } ;
15021470 }
15031471
1504- static scoreDescription ( ) {
1505- return [ "Startup" , "Runtime" , "Score" ] ;
1506- }
1507-
15081472 get startupID ( ) {
15091473 return `wasm-startup-id${ this . name } ` ;
15101474 }
@@ -1539,7 +1503,7 @@ class WasmLegacyBenchmark extends Benchmark {
15391503 console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
15401504 console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
15411505 }
1542- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1506+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
15431507 }
15441508} ;
15451509
0 commit comments