@@ -362,7 +362,7 @@ export class BenchmarkRunner {
362362 const iterationEndLabel = "iteration-end" ;
363363 for ( let i = 0 ; i < this . _iterationCount ; i ++ ) {
364364 performance . mark ( iterationStartLabel ) ;
365- await this . _runAllSuites ( ) ;
365+ await this . runAllSuites ( ) ;
366366 performance . mark ( iterationEndLabel ) ;
367367 performance . measure ( `iteration-${ i } ` , iterationStartLabel , iterationEndLabel ) ;
368368 }
@@ -375,7 +375,7 @@ export class BenchmarkRunner {
375375 }
376376 }
377377
378- async _appendFrame ( src ) {
378+ async _appendFrame ( ) {
379379 const frame = document . createElement ( "iframe" ) ;
380380 const style = frame . style ;
381381 style . width = `${ params . viewport . width } px` ;
@@ -396,7 +396,7 @@ export class BenchmarkRunner {
396396 return frame ;
397397 }
398398
399- async _runAllSuites ( ) {
399+ async _prepareAllSuites ( ) {
400400 this . _measuredValues = { tests : { } , total : 0 , mean : NaN , geomean : NaN , score : NaN } ;
401401
402402 const prepareStartLabel = "runner-prepare-start" ;
@@ -408,23 +408,32 @@ export class BenchmarkRunner {
408408 this . _page = new Page ( this . _frame ) ;
409409
410410 let suites = [ ...this . _suites ] ;
411- if ( this . _suiteOrderRandomNumberGenerator ) {
412- // We just do a simple Fisher-Yates shuffle based on the repeated hash of the
413- // seed. This is not a high quality RNG, but it's plenty good enough.
414- for ( let i = 0 ; i < suites . length - 1 ; i ++ ) {
415- let j = i + ( this . _suiteOrderRandomNumberGenerator ( ) % ( suites . length - i ) ) ;
416- let tmp = suites [ i ] ;
417- suites [ i ] = suites [ j ] ;
418- suites [ j ] = tmp ;
419- }
420- }
411+ if ( this . _suiteOrderRandomNumberGenerator )
412+ this . _shuffleSuites ( suites ) ;
413+
421414 performance . mark ( prepareEndLabel ) ;
422415 performance . measure ( "runner-prepare" , prepareStartLabel , prepareEndLabel ) ;
423416
417+ return suites ;
418+ }
419+
420+ _shuffleSuites ( suites ) {
421+ // We just do a simple Fisher-Yates shuffle based on the repeated hash of the
422+ // seed. This is not a high quality RNG, but it's plenty good enough.
423+ for ( let i = 0 ; i < suites . length - 1 ; i ++ ) {
424+ const j = i + ( this . _suiteOrderRandomNumberGenerator ( ) % ( suites . length - i ) ) ;
425+ const tmp = suites [ i ] ;
426+ suites [ i ] = suites [ j ] ;
427+ suites [ j ] = tmp ;
428+ }
429+ }
430+
431+ async runAllSuites ( ) {
432+ const suites = await this . _prepareAllSuites ( ) ;
424433 try {
425434 for ( const suite of suites ) {
426435 if ( ! suite . disabled )
427- await this . _runSuite ( suite ) ;
436+ await this . runSuite ( suite ) ;
428437 }
429438
430439 } finally {
@@ -444,23 +453,34 @@ export class BenchmarkRunner {
444453 performance . measure ( "runner-finalize" , finalizeStartLabel , finalizeEndLabel ) ;
445454 }
446455
447- async _runSuite ( suite ) {
456+ async runSuite ( suite ) {
457+ await this . _prepareSuite ( suite ) ;
458+ await this . _runSuite ( suite ) ;
459+ }
460+
461+ async _prepareSuite ( suite ) {
448462 const suiteName = suite . name ;
449463 const suitePrepareStartLabel = `suite-${ suiteName } -prepare-start` ;
450464 const suitePrepareEndLabel = `suite-${ suiteName } -prepare-end` ;
451- const suiteStartLabel = `suite-${ suiteName } -start` ;
452- const suiteEndLabel = `suite-${ suiteName } -end` ;
453465
454466 performance . mark ( suitePrepareStartLabel ) ;
455- await this . _prepareSuite ( suite ) ;
467+ await this . _loadFrame ( suite ) ;
468+ await suite . prepare ( this . _page ) ;
456469 performance . mark ( suitePrepareEndLabel ) ;
457470
471+ performance . measure ( `suite-${ suiteName } -prepare` , suitePrepareStartLabel , suitePrepareEndLabel ) ;
472+ }
473+
474+ async _runSuite ( suite ) {
475+ const suiteName = suite . name ;
476+ const suiteStartLabel = `suite-${ suiteName } -start` ;
477+ const suiteEndLabel = `suite-${ suiteName } -end` ;
478+
458479 performance . mark ( suiteStartLabel ) ;
459480 for ( const test of suite . tests )
460481 await this . _runTestAndRecordResults ( suite , test ) ;
461482 performance . mark ( suiteEndLabel ) ;
462483
463- performance . measure ( `suite-${ suiteName } -prepare` , suitePrepareStartLabel , suitePrepareEndLabel ) ;
464484 performance . measure ( `suite-${ suiteName } ` , suiteStartLabel , suiteEndLabel ) ;
465485 this . _validateSuiteTotal ( suiteName ) ;
466486 }
@@ -474,14 +494,12 @@ export class BenchmarkRunner {
474494 throw new Error ( `Got invalid 0-time total for suite ${ suiteName } : ${ suiteTotal } ` ) ;
475495 }
476496
477- async _prepareSuite ( suite ) {
478- return new Promise ( ( resolve ) => {
497+ async _loadFrame ( suite ) {
498+ return new Promise ( ( resolve , reject ) => {
479499 const frame = this . _page . _frame ;
480- frame . onload = async ( ) => {
481- await suite . prepare ( this . _page ) ;
482- resolve ( ) ;
483- } ;
484- frame . src = `${ suite . url } ` ;
500+ frame . onload = ( ) => resolve ( ) ;
501+ frame . onerror = ( ) => reject ( ) ;
502+ frame . src = suite . url ;
485503 } ) ;
486504 }
487505
0 commit comments