@@ -281,35 +281,10 @@ class Driver {
281
281
}
282
282
}
283
283
284
- prepareToRun ( ) {
285
- this . benchmarks . sort ( ( a , b ) => a . plan . name . toLowerCase ( ) < b . plan . name . toLowerCase ( ) ? 1 : - 1 ) ;
286
-
284
+ prepareBrowserUI ( ) {
287
285
let text = "" ;
288
- for ( const benchmark of this . benchmarks ) {
289
- const description = Object . keys ( benchmark . subScores ( ) ) ;
290
- description . push ( "Score" ) ;
291
-
292
- const scoreIds = benchmark . scoreIdentifiers ( ) ;
293
- const overallScoreId = scoreIds . pop ( ) ;
294
-
295
- if ( isInBrowser ) {
296
- text +=
297
- `<div class="benchmark" id="benchmark-${ benchmark . name } ">
298
- <h3 class="benchmark-name">${ benchmark . name } <a class="info" href="in-depth.html#${ benchmark . name } ">i</a></h3>
299
- <h4 class="score" id="${ overallScoreId } "> </h4>
300
- <h4 class="plot" id="plot-${ benchmark . name } "> </h4>
301
- <p>` ;
302
- for ( let i = 0 ; i < scoreIds . length ; i ++ ) {
303
- const scoreId = scoreIds [ i ] ;
304
- const label = description [ i ] ;
305
- text += `<span class="result"><span id="${ scoreId } "> </span><label>${ label } </label></span>`
306
- }
307
- text += `</p></div>` ;
308
- }
309
- }
310
-
311
- if ( ! isInBrowser )
312
- return ;
286
+ for ( const benchmark of this . benchmarks )
287
+ text += benchmark . renderHTML ( ) ;
313
288
314
289
const timestamp = performance . now ( ) ;
315
290
document . getElementById ( 'jetstreams' ) . style . backgroundImage = `url('jetstreams.svg?${ timestamp } ')` ;
@@ -349,7 +324,9 @@ class Driver {
349
324
if ( isInBrowser )
350
325
window . addEventListener ( "error" , ( e ) => this . pushError ( "driver startup" , e . error ) ) ;
351
326
await this . prefetchResources ( ) ;
352
- this . prepareToRun ( ) ;
327
+ this . benchmarks . sort ( ( a , b ) => a . plan . name . toLowerCase ( ) < b . plan . name . toLowerCase ( ) ? 1 : - 1 ) ;
328
+ if ( isInBrowser )
329
+ this . prepareBrowserUI ( ) ;
353
330
this . isReady = true ;
354
331
if ( isInBrowser ) {
355
332
globalThis . dispatchEvent ( new Event ( "JetStreamReady" ) ) ;
@@ -763,6 +740,26 @@ class Benchmark {
763
740
return code ;
764
741
}
765
742
743
+ renderHTML ( ) {
744
+ const description = Object . keys ( this . subScores ( ) ) ;
745
+ description . push ( "Score" ) ;
746
+
747
+ const scoreIds = this . scoreIdentifiers ( ) ;
748
+ const overallScoreId = scoreIds . pop ( ) ;
749
+ let text = `<div class="benchmark" id="benchmark-${ this . name } ">
750
+ <h3 class="benchmark-name">${ this . name } <a class="info" href="in-depth.html#${ this . name } ">i</a></h3>
751
+ <h4 class="score" id="${ overallScoreId } "> </h4>
752
+ <h4 class="plot" id="plot-${ this . name } "> </h4>
753
+ <p>` ;
754
+ for ( let i = 0 ; i < scoreIds . length ; i ++ ) {
755
+ const scoreId = scoreIds [ i ] ;
756
+ const label = description [ i ] ;
757
+ text += `<span class="result"><span id="${ scoreId } "> </span><label>${ label } </label></span>`
758
+ }
759
+ text += `</p></div>` ;
760
+ return text ;
761
+ }
762
+
766
763
async run ( ) {
767
764
if ( this . isDone )
768
765
throw new Error ( `Cannot run Benchmark ${ this . name } twice` ) ;
@@ -1012,11 +1009,15 @@ class Benchmark {
1012
1009
1013
1010
updateUIBeforeRun ( ) {
1014
1011
if ( ! JetStreamParams . dumpJSONResults )
1015
- console . log ( `Running ${ this . name } :` ) ;
1012
+ this . updateConsoleBeforeRun ( ) ;
1016
1013
if ( isInBrowser )
1017
1014
this . updateUIBeforeRunInBrowser ( ) ;
1018
1015
}
1019
1016
1017
+ updateConsoleBeforeRun ( ) {
1018
+ console . log ( `Running ${ this . name } :` ) ;
1019
+ }
1020
+
1020
1021
updateUIBeforeRunInBrowser ( ) {
1021
1022
const resultsBenchmarkUI = document . getElementById ( `benchmark-${ this . name } ` ) ;
1022
1023
resultsBenchmarkUI . classList . add ( "benchmark-running" ) ;
@@ -1112,6 +1113,26 @@ class GroupedBenchmark extends Benchmark {
1112
1113
for ( const benchmark of this . benchmarks )
1113
1114
benchmark . prefetchResourcesForShell ( ) ;
1114
1115
}
1116
+
1117
+ renderHTML ( ) {
1118
+ let text = super . renderHTML ( ) ;
1119
+ if ( JetStreamParams . groupDetails ) {
1120
+ for ( const benchmark of this . benchmarks )
1121
+ text += benchmark . renderHTML ( ) ;
1122
+ }
1123
+ return text ;
1124
+ }
1125
+
1126
+ updateConsoleBeforeRun ( ) {
1127
+ if ( ! JetStreamParams . groupDetails )
1128
+ super . updateConsoleBeforeRun ( ) ;
1129
+ }
1130
+
1131
+ updateConsoleAfterRun ( scoreEntries ) {
1132
+ if ( JetStreamParams . groupDetails )
1133
+ super . updateConsoleBeforeRun ( ) ;
1134
+ super . updateConsoleAfterRun ( scoreEntries ) ;
1135
+ }
1115
1136
1116
1137
get files ( ) {
1117
1138
let files = [ ] ;
@@ -1128,8 +1149,13 @@ class GroupedBenchmark extends Benchmark {
1128
1149
let benchmark ;
1129
1150
try {
1130
1151
this . _state = BenchmarkState . RUNNING ;
1131
- for ( benchmark of this . benchmarks )
1152
+ for ( benchmark of this . benchmarks ) {
1153
+ if ( JetStreamParams . groupDetails )
1154
+ benchmark . updateUIBeforeRun ( ) ;
1132
1155
await benchmark . run ( ) ;
1156
+ if ( JetStreamParams . groupDetails )
1157
+ benchmark . updateUIAfterRun ( ) ;
1158
+ }
1133
1159
} catch ( e ) {
1134
1160
this . _state = BenchmarkState . ERROR ;
1135
1161
console . log ( `Error in runCode of grouped benchmark ${ benchmark . name } : ` , e ) ;
0 commit comments