@@ -341,7 +341,7 @@ class Driver {
341
341
342
342
if ( isInBrowser ) {
343
343
globalThis . dispatchEvent ( new CustomEvent ( "JetStreamDone" , {
344
- detail : this . resultsObjectNew ( )
344
+ detail : this . resultsObject ( )
345
345
} ) ) ;
346
346
}
347
347
}
@@ -528,28 +528,30 @@ class Driver {
528
528
}
529
529
}
530
530
531
- resultsObject ( newStyle = false ) {
532
- if ( newStyle )
533
- return this . resultsObjectNew ( ) ;
534
- return this . resultsObjectOld ( ) ;
535
- }
536
-
537
- resultsObjectNew ( ) {
531
+ resultsObject ( format = "run-benchmark" ) {
532
+ if ( format == "run-benchmark" )
533
+ return this . runBenchmarkResultsObject ( ) ;
534
+ if ( format != "simple" )
535
+ throw Error ( `Unknown result format '${ format } '` ) ;
538
536
const results = { __proto__ : null } ;
539
537
for ( const benchmark of this . benchmarks ) {
540
538
if ( ! benchmark . isDone )
541
539
continue ;
542
- results [ benchmark . name ] = {
543
- Score : benchmark . score ,
544
- ...benchmark . subScores ( ) ,
540
+ if ( ! benchmark . isSuccess ) {
541
+ results [ benchmark . name ] = "FAILED" ;
542
+ } else {
543
+ results [ benchmark . name ] = {
544
+ Score : benchmark . score ,
545
+ ...benchmark . subScores ( ) ,
545
546
546
- } ;
547
+ } ;
548
+ }
547
549
}
548
550
return results ;
549
551
}
550
552
551
553
552
- resultsObjectOld ( )
554
+ runBenchmarkResultsObject ( )
553
555
{
554
556
let results = { } ;
555
557
for ( const benchmark of this . benchmarks ) {
@@ -571,9 +573,9 @@ class Driver {
571
573
return results ;
572
574
}
573
575
574
- resultsJSON ( )
576
+ resultsJSON ( format = "run-benchmark" )
575
577
{
576
- return JSON . stringify ( this . resultsObject ( ) ) ;
578
+ return JSON . stringify ( this . resultsObject ( format ) ) ;
577
579
}
578
580
579
581
dumpJSONResultsIfNeeded ( )
@@ -606,6 +608,15 @@ class Driver {
606
608
}
607
609
} ;
608
610
611
+ const BenchmarkState = Object . freeze ( {
612
+ READY : "READY" ,
613
+ SETUP : "SETUP" ,
614
+ RUNNING : "RUNNING" ,
615
+ FINALIZE : "FINALIZE" ,
616
+ ERROR : "ERROR" ,
617
+ DONE : "DONE"
618
+ } )
619
+
609
620
class Benchmark {
610
621
constructor ( plan )
611
622
{
@@ -618,12 +629,15 @@ class Benchmark {
618
629
this . scripts = null ;
619
630
620
631
this . _resourcesPromise = null ;
621
- this . _isDone = false ;
632
+ this . _state = BenchmarkState . READY ;
622
633
}
623
634
624
635
get name ( ) { return this . plan . name ; }
625
636
626
- get isDone ( ) { return this . _isDone ; }
637
+ get isDone ( ) {
638
+ return this . _state == BenchmarkState . DONE || this . _state == BenchmarkState . ERROR ;
639
+ }
640
+ get isSuccess ( ) { return this . _state = BenchmarkState . DONE ; }
627
641
628
642
get runnerCode ( ) {
629
643
return `
@@ -688,6 +702,7 @@ class Benchmark {
688
702
async run ( ) {
689
703
if ( this . isDone )
690
704
throw new Error ( `Cannot run Benchmark ${ this . name } twice` ) ;
705
+ this . _state = BenchmarkState . PREPARE ;
691
706
let code ;
692
707
if ( isInBrowser )
693
708
code = "" ;
@@ -796,16 +811,19 @@ class Benchmark {
796
811
797
812
let magicFrame ;
798
813
try {
814
+ this . _state = BenchmarkState . RUNNING ;
799
815
magicFrame = JetStream . runCode ( code ) ;
800
816
} catch ( e ) {
817
+ this . _state = BenchmarkState . ERROR ;
801
818
console . log ( "Error in runCode: " , e ) ;
802
819
console . log ( e . stack )
803
820
throw e ;
821
+ } finally {
822
+ this . _state = BenchmarkState . FINALIZE ;
804
823
}
805
824
const results = await promise ;
806
825
807
826
this . endTime = performance . now ( ) ;
808
- this . _isDone = true ;
809
827
810
828
if ( RAMification ) {
811
829
const memoryFootprint = MemoryFootprint ( ) ;
@@ -814,6 +832,8 @@ class Benchmark {
814
832
}
815
833
816
834
this . processResults ( results ) ;
835
+ this . _state = BenchmarkState . DONE ;
836
+
817
837
if ( isInBrowser )
818
838
magicFrame . contentDocument . close ( ) ;
819
839
else if ( isD8 )
0 commit comments