@@ -126,21 +126,6 @@ function assert(b, m = "") {
126
126
throw new Error ( `Bad assertion: ${ m } ` ) ;
127
127
}
128
128
129
- function firstID ( benchmark ) {
130
- return `results-cell-${ benchmark . name } -first` ;
131
- }
132
-
133
- function worst4ID ( benchmark ) {
134
- return `results-cell-${ benchmark . name } -worst4` ;
135
- }
136
-
137
- function avgID ( benchmark ) {
138
- return `results-cell-${ benchmark . name } -avg` ;
139
- }
140
-
141
- function scoreID ( benchmark ) {
142
- return `results-cell-${ benchmark . name } -score` ;
143
- }
144
129
145
130
function mean ( values ) {
146
131
assert ( values instanceof Array ) ;
@@ -679,9 +664,20 @@ class Benchmark {
679
664
}
680
665
681
666
get score ( ) {
667
+ const subScores = Object . values ( this . subScores ( ) ) ;
668
+ return geomean ( subScores ) ;
669
+ }
670
+
671
+ subScores ( ) {
682
672
throw new Error ( "Subclasses need to implement this" ) ;
683
673
}
684
674
675
+ allScores ( ) {
676
+ const allScores = this . subScores ( ) ;
677
+ allScores [ "Score" ] = this . score ;
678
+ return allScores ;
679
+ }
680
+
685
681
get prerunCode ( ) { return null ; }
686
682
687
683
get preIterationCode ( ) {
@@ -993,15 +989,23 @@ class Benchmark {
993
989
this . preloads = Object . entries ( this . plan . preload ?? { } ) ;
994
990
}
995
991
996
- scoreIdentifiers ( ) { throw new Error ( "Must be implemented by subclasses" ) ; }
992
+ scoreIdentifiers ( ) {
993
+ const ids = Object . keys ( this . allScores ( ) ) . map ( name => this . scoreIdentifier ( name ) ) ;
994
+ return ids ;
995
+ }
996
+
997
+ scoreIdentifier ( scoreName ) {
998
+ return `results-cell-${ this . name } -${ scoreName } ` ;
999
+ }
997
1000
998
1001
updateUIBeforeRun ( ) {
999
- if ( ! isInBrowser ) {
1000
- if ( ! dumpJSONResults )
1001
- console . log ( `Running ${ this . name } :` ) ;
1002
- return ;
1003
- }
1002
+ if ( ! dumpJSONResults )
1003
+ console . log ( `Running ${ this . name } :` ) ;
1004
+ if ( isInBrowser )
1005
+ this . updateUIBeforeRunInBrowser ( ) ;
1006
+ }
1004
1007
1008
+ updateUIBeforeRunInBrowser ( ) {
1005
1009
const containerUI = document . getElementById ( "results" ) ;
1006
1010
const resultsBenchmarkUI = document . getElementById ( `benchmark-${ this . name } ` ) ;
1007
1011
containerUI . insertBefore ( resultsBenchmarkUI , containerUI . firstChild ) ;
@@ -1012,13 +1016,43 @@ class Benchmark {
1012
1016
}
1013
1017
1014
1018
updateUIAfterRun ( ) {
1015
- if ( ! isInBrowser )
1019
+ const scoreEntries = Object . entries ( this . allScores ( ) ) ;
1020
+ if ( isInBrowser )
1021
+ this . updateUIAfterRunInBrowser ( scoreEntries ) ;
1022
+ if ( dumpJSONResults )
1016
1023
return ;
1024
+ this . updateConsoleAfterRun ( scoreEntries ) ;
1025
+ }
1017
1026
1027
+ updateUIAfterRunInBrowser ( scoreEntries ) {
1018
1028
const benchmarkResultsUI = document . getElementById ( `benchmark-${ this . name } ` ) ;
1019
1029
benchmarkResultsUI . classList . remove ( "benchmark-running" ) ;
1020
1030
benchmarkResultsUI . classList . add ( "benchmark-done" ) ;
1021
1031
1032
+ for ( const [ name , value ] of scoreEntries )
1033
+ document . getElementById ( this . scoreIdentifier ( name ) ) . innerHTML = uiFriendlyScore ( value ) ;
1034
+ }
1035
+
1036
+ updateConsoleAfterRun ( scoreEntries ) {
1037
+ // FIXME: consider removing this mapping.
1038
+ // Rename for backwards compatibility.
1039
+ const legacyScoreNameMap = {
1040
+ __proto__ : null ,
1041
+ "First" : "Startup" ,
1042
+ "Worst" : "Worst Case" ,
1043
+ "MainRun" : "Tests" ,
1044
+ "Runtime" : "Run time" ,
1045
+ } ;
1046
+ for ( let [ name , value ] of scoreEntries ) {
1047
+ if ( name in legacyScoreNameMap )
1048
+ name = legacyScoreNameMap [ name ] ;
1049
+ console . log ( ` ${ name } :` , uiFriendlyScore ( value ) ) ;
1050
+ }
1051
+ if ( RAMification ) {
1052
+ console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1053
+ console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1054
+ }
1055
+ console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1022
1056
}
1023
1057
} ;
1024
1058
@@ -1063,46 +1097,13 @@ class DefaultBenchmark extends Benchmark {
1063
1097
this . averageScore = toScore ( this . averageTime ) ;
1064
1098
}
1065
1099
1066
- get score ( ) {
1067
- return geomean ( [ this . firstIterationScore , this . worst4Score , this . averageScore ] ) ;
1068
- }
1069
-
1070
1100
subScores ( ) {
1071
1101
return {
1072
1102
"First" : this . firstIterationScore ,
1073
1103
"Worst" : this . worst4Score ,
1074
1104
"Average" : this . averageScore ,
1075
1105
} ;
1076
1106
}
1077
-
1078
- scoreIdentifiers ( ) {
1079
- return [ firstID ( this ) , worst4ID ( this ) , avgID ( this ) , scoreID ( this ) ] ;
1080
- }
1081
-
1082
- updateUIAfterRun ( ) {
1083
- super . updateUIAfterRun ( ) ;
1084
-
1085
- if ( isInBrowser ) {
1086
- document . getElementById ( firstID ( this ) ) . innerHTML = uiFriendlyScore ( this . firstIterationScore ) ;
1087
- document . getElementById ( worst4ID ( this ) ) . innerHTML = uiFriendlyScore ( this . worst4Score ) ;
1088
- document . getElementById ( avgID ( this ) ) . innerHTML = uiFriendlyScore ( this . averageScore ) ;
1089
- document . getElementById ( scoreID ( this ) ) . innerHTML = uiFriendlyScore ( this . score ) ;
1090
- return ;
1091
- }
1092
-
1093
- if ( dumpJSONResults )
1094
- return ;
1095
-
1096
- console . log ( " Startup:" , uiFriendlyScore ( this . firstIterationScore ) ) ;
1097
- console . log ( " Worst Case:" , uiFriendlyScore ( this . worst4Score ) ) ;
1098
- console . log ( " Average:" , uiFriendlyScore ( this . averageScore ) ) ;
1099
- console . log ( " Score:" , uiFriendlyScore ( this . score ) ) ;
1100
- if ( RAMification ) {
1101
- console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1102
- console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1103
- }
1104
- console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1105
- }
1106
1107
}
1107
1108
1108
1109
class AsyncBenchmark extends DefaultBenchmark {
@@ -1250,10 +1251,6 @@ class WSLBenchmark extends Benchmark {
1250
1251
this . mainRunScore = toScore ( results [ 1 ] ) ;
1251
1252
}
1252
1253
1253
- get score ( ) {
1254
- return geomean ( [ this . stdlibScore , this . mainRunScore ] ) ;
1255
- }
1256
-
1257
1254
get runnerCode ( ) {
1258
1255
return `
1259
1256
let benchmark = new Benchmark();
@@ -1292,33 +1289,6 @@ class WSLBenchmark extends Benchmark {
1292
1289
"MainRun" : this . mainRunScore ,
1293
1290
} ;
1294
1291
}
1295
-
1296
- scoreIdentifiers ( ) {
1297
- return [ "wsl-stdlib-score" , "wsl-tests-score" , "wsl-score-score" ] ;
1298
- }
1299
-
1300
- updateUIAfterRun ( ) {
1301
- super . updateUIAfterRun ( ) ;
1302
-
1303
- if ( isInBrowser ) {
1304
- document . getElementById ( "wsl-stdlib-score" ) . innerHTML = uiFriendlyScore ( this . stdlibScore ) ;
1305
- document . getElementById ( "wsl-tests-score" ) . innerHTML = uiFriendlyScore ( this . mainRunScore ) ;
1306
- document . getElementById ( "wsl-score-score" ) . innerHTML = uiFriendlyScore ( this . score ) ;
1307
- return ;
1308
- }
1309
-
1310
- if ( dumpJSONResults )
1311
- return ;
1312
-
1313
- console . log ( " Stdlib:" , uiFriendlyScore ( this . stdlibScore ) ) ;
1314
- console . log ( " Tests:" , uiFriendlyScore ( this . mainRunScore ) ) ;
1315
- console . log ( " Score:" , uiFriendlyScore ( this . score ) ) ;
1316
- if ( RAMification ) {
1317
- console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1318
- console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1319
- }
1320
- console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1321
- }
1322
1292
} ;
1323
1293
1324
1294
class WasmLegacyBenchmark extends Benchmark {
@@ -1338,10 +1308,6 @@ class WasmLegacyBenchmark extends Benchmark {
1338
1308
this . runScore = toScore ( results [ 1 ] ) ;
1339
1309
}
1340
1310
1341
- get score ( ) {
1342
- return geomean ( [ this . startupScore , this . runScore ] ) ;
1343
- }
1344
-
1345
1311
get prerunCode ( ) {
1346
1312
const str = `
1347
1313
let verbose = false;
@@ -1464,43 +1430,6 @@ class WasmLegacyBenchmark extends Benchmark {
1464
1430
"Runtime" : this . runScore ,
1465
1431
} ;
1466
1432
}
1467
-
1468
- get startupID ( ) {
1469
- return `wasm-startup-id${ this . name } ` ;
1470
- }
1471
- get runID ( ) {
1472
- return `wasm-run-id${ this . name } ` ;
1473
- }
1474
- get scoreID ( ) {
1475
- return `wasm-score-id${ this . name } ` ;
1476
- }
1477
-
1478
- scoreIdentifiers ( ) {
1479
- return [ this . startupID , this . runID , this . scoreID ] ;
1480
- }
1481
-
1482
- updateUIAfterRun ( ) {
1483
- super . updateUIAfterRun ( ) ;
1484
-
1485
- if ( isInBrowser ) {
1486
- document . getElementById ( this . startupID ) . innerHTML = uiFriendlyScore ( this . startupScore ) ;
1487
- document . getElementById ( this . runID ) . innerHTML = uiFriendlyScore ( this . runScore ) ;
1488
- document . getElementById ( this . scoreID ) . innerHTML = uiFriendlyScore ( this . score ) ;
1489
- return ;
1490
- }
1491
-
1492
- if ( dumpJSONResults )
1493
- return ;
1494
-
1495
- console . log ( " Startup:" , uiFriendlyScore ( this . startupScore ) ) ;
1496
- console . log ( " Run time:" , uiFriendlyScore ( this . runScore ) ) ;
1497
- console . log ( " Score:" , uiFriendlyScore ( this . score ) ) ;
1498
- if ( RAMification ) {
1499
- console . log ( " Current Footprint:" , uiFriendlyNumber ( this . currentFootprint ) ) ;
1500
- console . log ( " Peak Footprint:" , uiFriendlyNumber ( this . peakFootprint ) ) ;
1501
- }
1502
- console . log ( " Wall time:" , uiFriendlyDuration ( this . endTime - this . startTime ) ) ;
1503
- }
1504
1433
} ;
1505
1434
1506
1435
function dotnetPreloads ( type )
0 commit comments