@@ -115,7 +115,7 @@ if (isInBrowser) {
115
115
116
116
function assert ( b , m = "" ) {
117
117
if ( ! b )
118
- throw new Error ( " Bad assertion: " + m ) ;
118
+ throw new Error ( ` Bad assertion: ${ m } ` ) ;
119
119
}
120
120
121
121
function firstID ( benchmark ) {
@@ -177,17 +177,8 @@ function uiFriendlyScore(num) {
177
177
return uiFriendlyNumber ( num ) ;
178
178
}
179
179
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` ;
191
182
}
192
183
193
184
const fileLoader = ( function ( ) {
@@ -321,7 +312,7 @@ class Driver {
321
312
322
313
if ( isInBrowser ) {
323
314
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>` ;
325
316
summaryElement . onclick = displayCategoryScores ;
326
317
if ( showScoreDetails )
327
318
displayCategoryScores ( ) ;
@@ -391,7 +382,7 @@ class Driver {
391
382
392
383
const magicFrame = magic . contentDocument . getElementById ( "magicframe" ) ;
393
384
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>` ) ;
395
386
396
387
return magicFrame ;
397
388
}
@@ -403,11 +394,11 @@ class Driver {
403
394
let text = "" ;
404
395
let newBenchmarks = [ ] ;
405
396
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" ) ;
408
399
409
400
newBenchmarks . push ( benchmark ) ;
410
- const scoreIds = benchmark . scoreIdentifiers ( )
401
+ const scoreIds = benchmark . scoreIdentifiers ( ) ;
411
402
const overallScoreId = scoreIds . pop ( ) ;
412
403
413
404
if ( isInBrowser ) {
@@ -650,9 +641,6 @@ class Benchmark {
650
641
let benchmarkName = "${ this . name } ";
651
642
652
643
for (let i = 0; i < ${ this . iterations } ; i++) {
653
- if (__benchmark.prepareForNextIteration)
654
- __benchmark.prepareForNextIteration();
655
-
656
644
${ this . preIterationCode }
657
645
658
646
const iterationMarkLabel = benchmarkName + "-iteration-" + i;
@@ -662,14 +650,13 @@ class Benchmark {
662
650
__benchmark.runIteration();
663
651
let end = performance.now();
664
652
665
- performanceMeasure (iterationMarkLabel, iterationStartMark );
653
+ performance.measure (iterationMarkLabel, iterationMarkLabel );
666
654
667
655
${ this . postIterationCode }
668
656
669
657
results.push(Math.max(1, end - start));
670
658
}
671
- if (__benchmark.validate)
672
- __benchmark.validate(${ this . iterations } );
659
+ __benchmark.validate?.(${ this . iterations } );
673
660
top.currentResolve(results);` ;
674
661
}
675
662
@@ -684,7 +671,7 @@ class Benchmark {
684
671
get prerunCode ( ) { return null ; }
685
672
686
673
get preIterationCode ( ) {
687
- let code = "" ;
674
+ let code = `__benchmark.prepareForNextIteration?.();` ;
688
675
if ( this . plan . deterministicRandom )
689
676
code += `Math.random.__resetSeed();` ;
690
677
@@ -731,19 +718,11 @@ class Benchmark {
731
718
const isInBrowser = ${ isInBrowser } ;
732
719
const isD8 = ${ isD8 } ;
733
720
if (typeof performance.mark === 'undefined') {
734
- performance.mark = function() {};
721
+ performance.mark = function(name ) { return { name } };
735
722
}
736
723
if (typeof performance.measure === 'undefined') {
737
724
performance.measure = function() {};
738
725
}
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
- }
747
726
` ) ;
748
727
749
728
if ( ! ! this . plan . deterministicRandom ) {
@@ -1018,7 +997,6 @@ class Benchmark {
1018
997
return this . _resourcesPromise ;
1019
998
}
1020
999
1021
- static scoreDescription ( ) { throw new Error ( "Must be implemented by subclasses." ) ; }
1022
1000
scoreIdentifiers ( ) { throw new Error ( "Must be implemented by subclasses" ) ; }
1023
1001
1024
1002
updateUIBeforeRun ( ) {
@@ -1101,10 +1079,6 @@ class DefaultBenchmark extends Benchmark {
1101
1079
} ;
1102
1080
}
1103
1081
1104
- static scoreDescription ( ) {
1105
- return [ "First" , "Worst" , "Average" , "Score" ] ;
1106
- }
1107
-
1108
1082
scoreIdentifiers ( ) {
1109
1083
return [ firstID ( this ) , worst4ID ( this ) , avgID ( this ) , scoreID ( this ) ] ;
1110
1084
}
@@ -1131,7 +1105,7 @@ class DefaultBenchmark extends Benchmark {
1131
1105
console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1132
1106
console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1133
1107
}
1134
- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1108
+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1135
1109
}
1136
1110
}
1137
1111
@@ -1185,8 +1159,7 @@ class AsyncBenchmark extends DefaultBenchmark {
1185
1159
return `
1186
1160
async function doRun() {
1187
1161
let __benchmark = new Benchmark();
1188
- if (__benchmark.init)
1189
- await __benchmark.init();
1162
+ await __benchmark.init?.();
1190
1163
let results = [];
1191
1164
let benchmarkName = "${ this . name } ";
1192
1165
@@ -1200,14 +1173,13 @@ class AsyncBenchmark extends DefaultBenchmark {
1200
1173
await __benchmark.runIteration();
1201
1174
let end = performance.now();
1202
1175
1203
- performanceMeasure (iterationMarkLabel, iterationStartMark );
1176
+ performance.measure (iterationMarkLabel, iterationMarkLabel );
1204
1177
1205
1178
${ this . postIterationCode }
1206
1179
1207
1180
results.push(Math.max(1, end - start));
1208
1181
}
1209
- if (__benchmark.validate)
1210
- __benchmark.validate(${ this . iterations } );
1182
+ __benchmark.validate?.(${ this . iterations } );
1211
1183
top.currentResolve(results);
1212
1184
}
1213
1185
doRun().catch((error) => { top.currentReject(error); });`
@@ -1300,7 +1272,7 @@ class WSLBenchmark extends Benchmark {
1300
1272
benchmark.buildStdlib();
1301
1273
results.push(performance.now() - start);
1302
1274
1303
- performanceMeasure (markLabel, startMark );
1275
+ performance.measure (markLabel, markLabel );
1304
1276
}
1305
1277
1306
1278
{
@@ -1311,7 +1283,7 @@ class WSLBenchmark extends Benchmark {
1311
1283
benchmark.run();
1312
1284
results.push(performance.now() - start);
1313
1285
1314
- performanceMeasure (markLabel, startMark );
1286
+ performance.measure (markLabel, markLabel );
1315
1287
}
1316
1288
1317
1289
top.currentResolve(results);
@@ -1325,10 +1297,6 @@ class WSLBenchmark extends Benchmark {
1325
1297
} ;
1326
1298
}
1327
1299
1328
- static scoreDescription ( ) {
1329
- return [ "Stdlib" , "MainRun" , "Score" ] ;
1330
- }
1331
-
1332
1300
scoreIdentifiers ( ) {
1333
1301
return [ "wsl-stdlib-score" , "wsl-tests-score" , "wsl-score-score" ] ;
1334
1302
}
@@ -1353,7 +1321,7 @@ class WSLBenchmark extends Benchmark {
1353
1321
console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1354
1322
console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1355
1323
}
1356
- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1324
+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1357
1325
}
1358
1326
} ;
1359
1327
@@ -1501,10 +1469,6 @@ class WasmLegacyBenchmark extends Benchmark {
1501
1469
} ;
1502
1470
}
1503
1471
1504
- static scoreDescription ( ) {
1505
- return [ "Startup" , "Runtime" , "Score" ] ;
1506
- }
1507
-
1508
1472
get startupID ( ) {
1509
1473
return `wasm-startup-id${ this . name } ` ;
1510
1474
}
@@ -1539,7 +1503,7 @@ class WasmLegacyBenchmark extends Benchmark {
1539
1503
console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1540
1504
console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1541
1505
}
1542
- console . log ( " Wall time:" , uiFriendlyDuration ( new Date ( this . endTime - this . startTime ) ) ) ;
1506
+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1543
1507
}
1544
1508
} ;
1545
1509
0 commit comments