27
27
28
28
const measureTotalTimeAsSubtest = false ; // Once we move to preloading all resources, it would be good to turn this on.
29
29
30
+ const defaultIterationCount = 120 ;
31
+ const defaultWorstCaseCount = 4 ;
32
+
30
33
globalThis . performance ??= Date ;
31
34
globalThis . RAMification ??= false ;
32
35
globalThis . testIterationCount ??= undefined ;
33
36
globalThis . testIterationCountMap ??= new Map ( ) ;
37
+ globalThis . testWorstCaseCount ??= undefined ;
34
38
globalThis . testWorstCaseCountMap ??= new Map ( ) ;
35
39
globalThis . dumpJSONResults ??= false ;
36
40
globalThis . customTestList ??= [ ] ;
37
-
38
41
let shouldReport = false ;
42
+
43
+ function getIntParam ( urlParams , key ) {
44
+ if ( ! urlParams . has ( key ) )
45
+ return undefined
46
+ const rawValue = urlParams . get ( key ) ;
47
+ const value = parseInt ( rawValue ) ;
48
+ if ( value <= 0 )
49
+ throw new Error ( `Expected positive value for ${ key } , but got ${ rawValue } ` )
50
+ return value
51
+ }
52
+
39
53
if ( typeof ( URLSearchParams ) !== "undefined" ) {
40
54
const urlParameters = new URLSearchParams ( window . location . search ) ;
41
55
shouldReport = urlParameters . has ( 'report' ) && urlParameters . get ( 'report' ) . toLowerCase ( ) == 'true' ;
42
56
if ( urlParameters . has ( 'test' ) )
43
57
customTestList = urlParameters . getAll ( "test" ) ;
58
+ globalThis . testIterationCount = getIntParam ( urlParameters , "iterationCount" ) ;
59
+ globalThis . testWorstCaseCount = getIntParam ( urlParameters , "worstCaseCount" ) ;
44
60
}
45
61
62
+
63
+
46
64
// Used for the promise representing the current benchmark run.
47
65
this . currentResolve = null ;
48
66
this . currentReject = null ;
49
67
50
- const defaultIterationCount = 120 ;
51
- const defaultWorstCaseCount = 4 ;
52
-
53
68
let showScoreDetails = false ;
54
69
let categoryScores = null ;
55
70
@@ -77,6 +92,8 @@ function getIterationCount(plan) {
77
92
function getWorstCaseCount ( plan ) {
78
93
if ( testWorstCaseCountMap . has ( plan . name ) )
79
94
return testWorstCaseCountMap . get ( plan . name ) ;
95
+ if ( testWorstCaseCount )
96
+ return testWorstCaseCount ;
80
97
if ( plan . worstCaseCount )
81
98
return plan . worstCaseCount ;
82
99
return defaultWorstCaseCount ;
@@ -214,6 +231,7 @@ const fileLoader = (function() {
214
231
215
232
class Driver {
216
233
constructor ( ) {
234
+ this . isReady = false ;
217
235
this . benchmarks = [ ] ;
218
236
this . blobDataCache = { } ;
219
237
this . loadCache = { } ;
@@ -308,6 +326,11 @@ class Driver {
308
326
309
327
this . reportScoreToRunBenchmarkRunner ( ) ;
310
328
this . dumpJSONResultsIfNeeded ( ) ;
329
+ if ( isInBrowser ) {
330
+ globalThis . dispatchEvent ( new CustomEvent ( "JetStreamDone" , {
331
+ detail : this . resultsObject ( )
332
+ } ) ) ;
333
+ }
311
334
}
312
335
313
336
runCode ( string )
@@ -351,7 +374,6 @@ class Driver {
351
374
var magicFrame = magic . contentDocument . getElementById ( "magicframe" ) ;
352
375
magicFrame . contentDocument . open ( ) ;
353
376
magicFrame . contentDocument . write ( "<!DOCTYPE html><head><title>benchmark payload</title></head><body>\n" + string + "</body></html>" ) ;
354
-
355
377
return magicFrame ;
356
378
}
357
379
@@ -414,8 +436,12 @@ class Driver {
414
436
await this . prefetchResourcesForBrowser ( ) ;
415
437
await this . fetchResources ( ) ;
416
438
this . prepareToRun ( ) ;
417
- if ( isInBrowser && shouldReport ) {
418
- setTimeout ( ( ) => this . start ( ) , 4000 ) ;
439
+ this . isReady = true ;
440
+ if ( isInBrowser ) {
441
+ globalThis . dispatchEvent ( new Event ( "JetStreamReady" ) ) ;
442
+ if ( shouldReport ) {
443
+ setTimeout ( ( ) => this . start ( ) , 4000 ) ;
444
+ }
419
445
}
420
446
}
421
447
@@ -441,7 +467,7 @@ class Driver {
441
467
// If we've failed to prefetch resources even after a sequential 1 by 1 retry,
442
468
// then fail out early rather than letting subtests fail with a hang.
443
469
window . allIsGood = false ;
444
- throw new Error ( "Fetch failed" ) ;
470
+ throw new Error ( "Fetch failed" ) ;
445
471
}
446
472
}
447
473
@@ -467,7 +493,7 @@ class Driver {
467
493
}
468
494
}
469
495
470
- resultsJSON ( )
496
+ resultsObject ( )
471
497
{
472
498
let results = { } ;
473
499
for ( let benchmark of this . benchmarks ) {
@@ -486,8 +512,13 @@ class Driver {
486
512
}
487
513
488
514
results = { "JetStream3.0" : { "metrics" : { "Score" : [ "Geometric" ] } , "tests" : results } } ;
515
+ return results ;
489
516
490
- return JSON . stringify ( results ) ;
517
+ }
518
+
519
+ resultsJSON ( )
520
+ {
521
+ return JSON . stringify ( this . resultsObject ( ) ) ;
491
522
}
492
523
493
524
dumpJSONResultsIfNeeded ( )
@@ -525,6 +556,7 @@ class Benchmark {
525
556
{
526
557
this . plan = plan ;
527
558
this . iterations = getIterationCount ( plan ) ;
559
+ console . log ( { name :this . name , iterations :this . iterations } )
528
560
this . isAsync = ! ! plan . isAsync ;
529
561
530
562
this . scripts = null ;
@@ -547,11 +579,10 @@ class Benchmark {
547
579
let start = performance.now();
548
580
__benchmark.runIteration();
549
581
let end = performance.now();
550
-
551
582
results.push(Math.max(1, end - start));
552
583
}
553
584
if (__benchmark.validate)
554
- __benchmark.validate();
585
+ __benchmark.validate(${ this . iterations } );
555
586
top.currentResolve(results);` ;
556
587
}
557
588
@@ -804,7 +835,7 @@ class Benchmark {
804
835
805
836
if ( ! blobData . blob ) {
806
837
window . allIsGood = false ;
807
- throw new Error ( "Fetch failed" ) ;
838
+ throw new Error ( "Fetch failed" ) ;
808
839
}
809
840
810
841
return ! counter . failedPreloadResources && counter . loadedResources == counter . totalResources ;
@@ -858,11 +889,10 @@ class Benchmark {
858
889
scoreIdentifiers ( ) { throw new Error ( "Must be implemented by subclasses" ) ; }
859
890
860
891
updateUIBeforeRun ( ) {
861
- if ( ! isInBrowser ) {
862
- if ( ! dumpJSONResults )
863
- console . log ( `Running ${ this . name } :` ) ;
892
+ if ( ! dumpJSONResults )
893
+ console . log ( `Running ${ this . name } :` ) ;
894
+ if ( ! isInBrowser )
864
895
return ;
865
- }
866
896
867
897
let containerUI = document . getElementById ( "results" ) ;
868
898
let resultsBenchmarkUI = document . getElementById ( `benchmark-${ this . name } ` ) ;
@@ -947,7 +977,6 @@ class DefaultBenchmark extends Benchmark {
947
977
document . getElementById ( worst4ID ( this ) ) . innerHTML = uiFriendlyNumber ( this . worst4 ) ;
948
978
document . getElementById ( avgID ( this ) ) . innerHTML = uiFriendlyNumber ( this . average ) ;
949
979
document . getElementById ( scoreID ( this ) ) . innerHTML = uiFriendlyNumber ( this . score ) ;
950
- return ;
951
980
}
952
981
953
982
if ( dumpJSONResults )
@@ -979,7 +1008,7 @@ class AsyncBenchmark extends DefaultBenchmark {
979
1008
results.push(Math.max(1, end - start));
980
1009
}
981
1010
if (__benchmark.validate)
982
- __benchmark.validate();
1011
+ __benchmark.validate(${ this . iterations } );
983
1012
top.currentResolve(results);
984
1013
}
985
1014
doRun().catch((error) => { top.currentReject(error); });`
@@ -1045,7 +1074,6 @@ class WSLBenchmark extends Benchmark {
1045
1074
document . getElementById ( "wsl-stdlib-score" ) . innerHTML = uiFriendlyNumber ( this . stdlib ) ;
1046
1075
document . getElementById ( "wsl-tests-score" ) . innerHTML = uiFriendlyNumber ( this . mainRun ) ;
1047
1076
document . getElementById ( "wsl-score-score" ) . innerHTML = uiFriendlyNumber ( this . score ) ;
1048
- return ;
1049
1077
}
1050
1078
1051
1079
if ( dumpJSONResults )
@@ -1226,7 +1254,6 @@ class WasmBenchmark extends Benchmark {
1226
1254
document . getElementById ( this . startupID ) . innerHTML = uiFriendlyNumber ( this . startupTime ) ;
1227
1255
document . getElementById ( this . runID ) . innerHTML = uiFriendlyNumber ( this . runTime ) ;
1228
1256
document . getElementById ( this . scoreID ) . innerHTML = uiFriendlyNumber ( this . score ) ;
1229
- return ;
1230
1257
}
1231
1258
1232
1259
if ( dumpJSONResults )
0 commit comments