@@ -240,7 +240,7 @@ class Driver {
240
240
constructor ( ) {
241
241
this . isReady = false ;
242
242
this . isDone = false ;
243
- this . incrementalResults = [ ] ;
243
+ this . errors = [ ] ;
244
244
this . benchmarks = [ ] ;
245
245
this . blobDataCache = { } ;
246
246
this . loadCache = { } ;
@@ -276,21 +276,14 @@ class Driver {
276
276
try {
277
277
await benchmark . run ( ) ;
278
278
} catch ( e ) {
279
- JetStream . reportError ( benchmark ) ;
279
+ this . reportError ( benchmark , e ) ;
280
280
throw e ;
281
281
}
282
282
283
283
benchmark . updateUIAfterRun ( ) ;
284
284
console . log ( benchmark . name )
285
285
286
286
if ( isInBrowser ) {
287
- this . incrementalResults . push ( {
288
- name : benchmark . name ,
289
- results : {
290
- Score : benchmark . score ,
291
- ...benchmark . subScores ( ) ,
292
- }
293
- } ) ;
294
287
const cache = JetStream . blobDataCache ;
295
288
for ( const file of benchmark . plan . files ) {
296
289
const blobData = cache [ file ] ;
@@ -345,19 +338,14 @@ class Driver {
345
338
this . reportScoreToRunBenchmarkRunner ( ) ;
346
339
this . dumpJSONResultsIfNeeded ( ) ;
347
340
this . isDone = true ;
341
+
348
342
if ( isInBrowser ) {
349
343
globalThis . dispatchEvent ( new CustomEvent ( "JetStreamDone" , {
350
- detail : this . resultsObject ( )
344
+ detail : this . resultsObjectNew ( )
351
345
} ) ) ;
352
346
}
353
347
}
354
348
355
- drainIncrementalResults ( ) {
356
- const currentIncrementalResults = this . incrementalResults ;
357
- this . incrementalResults = [ ] ;
358
- return currentIncrementalResults
359
- }
360
-
361
349
runCode ( string )
362
350
{
363
351
if ( ! isInBrowser ) {
@@ -455,16 +443,31 @@ class Driver {
455
443
} ) ;
456
444
}
457
445
458
- reportError ( benchmark )
446
+ reportError ( benchmark , error )
459
447
{
448
+ this . pushError ( benchmark . name , error ) ;
449
+
460
450
if ( ! isInBrowser )
461
451
return ;
462
452
463
- for ( const id of benchmark . scoreIdentifiers ( ) )
453
+ for ( const id of benchmark . scoreIdentifiers ( ) ) {
464
454
document . getElementById ( id ) . innerHTML = "error" ;
455
+ const benchmarkResultsUI = document . getElementById ( `benchmark-${ benchmark . name } ` ) ;
456
+ benchmarkResultsUI . classList . remove ( "benchmark-running" ) ;
457
+ benchmarkResultsUI . classList . add ( "benchmark-error" ) ;
458
+ }
459
+ }
460
+
461
+ pushError ( name , error ) {
462
+ this . errors . push ( {
463
+ benchmark : name ,
464
+ error : error . toString ( ) ,
465
+ stack : error . stack
466
+ } ) ;
465
467
}
466
468
467
469
async initialize ( ) {
470
+ window . addEventListener ( "error" , ( e ) => this . pushError ( benchmark , e . error ) ) ;
468
471
await this . prefetchResourcesForBrowser ( ) ;
469
472
await this . fetchResources ( ) ;
470
473
this . prepareToRun ( ) ;
@@ -525,16 +528,43 @@ class Driver {
525
528
}
526
529
}
527
530
528
- resultsObject ( )
531
+ resultsObject ( newStyle = false ) {
532
+ if ( newStyle )
533
+ return this . resultsObjectNew ( ) ;
534
+ return this . resultsObjectOld ( ) ;
535
+ }
536
+
537
+ resultsObjectNew ( ) {
538
+ const results = { __proto__ : null } ;
539
+ for ( const benchmark of this . benchmarks ) {
540
+ if ( ! benchmark . isDone )
541
+ continue ;
542
+ results [ benchmark . name ] = {
543
+ Score : benchmark . score ,
544
+ ...benchmark . subScores ( ) ,
545
+
546
+ } ;
547
+ }
548
+ return results ;
549
+ }
550
+
551
+
552
+ resultsObjectOld ( )
529
553
{
530
- let results = { } ;
554
+ let testResults = { } ;
531
555
for ( const benchmark of this . benchmarks ) {
532
556
const subResults = { }
533
557
const subScores = benchmark . subScores ( ) ;
534
558
for ( const name in subScores ) {
535
- subResults [ name ] = { "metrics" : { "Time" : { "current" : [ toTimeValue ( subScores [ name ] ) ] } } } ;
559
+ subResults [ name ] = {
560
+ "metrics" : {
561
+ "Time" : {
562
+ "current" : [ toTimeValue ( subScores [ name ] ) ]
563
+ }
564
+ }
565
+ } ;
536
566
}
537
- results [ benchmark . name ] = {
567
+ testResults [ benchmark . name ] = {
538
568
"metrics" : {
539
569
"Score" : { "current" : [ benchmark . score ] } ,
540
570
"Time" : [ "Geometric" ] ,
@@ -543,9 +573,15 @@ class Driver {
543
573
} ;
544
574
}
545
575
546
- results = { "JetStream3.0" : { "metrics" : { "Score" : [ "Geometric" ] } , "tests" : results } } ;
576
+ const results = {
577
+ "JetStream3.0" : {
578
+ "metrics" : {
579
+ "Score" : [ "Geometric" ]
580
+ } ,
581
+ "tests" : testResults
582
+ }
583
+ } ;
547
584
return results ;
548
-
549
585
}
550
586
551
587
resultsJSON ( )
@@ -595,10 +631,13 @@ class Benchmark {
595
631
this . scripts = null ;
596
632
597
633
this . _resourcesPromise = null ;
634
+ this . _isDone = false ;
598
635
}
599
636
600
637
get name ( ) { return this . plan . name ; }
601
638
639
+ get isDone ( ) { return this . _isDone ; }
640
+
602
641
get runnerCode ( ) {
603
642
return `
604
643
let __benchmark = new Benchmark(${ this . iterations } );
@@ -660,6 +699,8 @@ class Benchmark {
660
699
}
661
700
662
701
async run ( ) {
702
+ if ( this . isDone )
703
+ throw new Error ( `Cannot run Benchmark ${ this . name } twice` ) ;
663
704
let code ;
664
705
if ( isInBrowser )
665
706
code = "" ;
@@ -777,6 +818,7 @@ class Benchmark {
777
818
const results = await promise ;
778
819
779
820
this . endTime = performance . now ( ) ;
821
+ this . _isDone = true ;
780
822
781
823
if ( RAMification ) {
782
824
const memoryFootprint = MemoryFootprint ( ) ;
0 commit comments