@@ -362,7 +362,7 @@ export class BenchmarkRunner {
362
362
const iterationEndLabel = "iteration-end" ;
363
363
for ( let i = 0 ; i < this . _iterationCount ; i ++ ) {
364
364
performance . mark ( iterationStartLabel ) ;
365
- await this . _runAllSuites ( ) ;
365
+ await this . runAllSuites ( ) ;
366
366
performance . mark ( iterationEndLabel ) ;
367
367
performance . measure ( `iteration-${ i } ` , iterationStartLabel , iterationEndLabel ) ;
368
368
}
@@ -375,7 +375,7 @@ export class BenchmarkRunner {
375
375
}
376
376
}
377
377
378
- async _appendFrame ( src ) {
378
+ async _appendFrame ( ) {
379
379
const frame = document . createElement ( "iframe" ) ;
380
380
const style = frame . style ;
381
381
style . width = `${ params . viewport . width } px` ;
@@ -396,7 +396,7 @@ export class BenchmarkRunner {
396
396
return frame ;
397
397
}
398
398
399
- async _runAllSuites ( ) {
399
+ async _prepareAllSuites ( ) {
400
400
this . _measuredValues = { tests : { } , total : 0 , mean : NaN , geomean : NaN , score : NaN } ;
401
401
402
402
const prepareStartLabel = "runner-prepare-start" ;
@@ -408,23 +408,32 @@ export class BenchmarkRunner {
408
408
this . _page = new Page ( this . _frame ) ;
409
409
410
410
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
+
421
414
performance . mark ( prepareEndLabel ) ;
422
415
performance . measure ( "runner-prepare" , prepareStartLabel , prepareEndLabel ) ;
423
416
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 ( ) ;
424
433
try {
425
434
for ( const suite of suites ) {
426
435
if ( ! suite . disabled )
427
- await this . _runSuite ( suite ) ;
436
+ await this . runSuite ( suite ) ;
428
437
}
429
438
430
439
} finally {
@@ -444,23 +453,34 @@ export class BenchmarkRunner {
444
453
performance . measure ( "runner-finalize" , finalizeStartLabel , finalizeEndLabel ) ;
445
454
}
446
455
447
- async _runSuite ( suite ) {
456
+ async runSuite ( suite ) {
457
+ await this . _prepareSuite ( suite ) ;
458
+ await this . _runSuite ( suite ) ;
459
+ }
460
+
461
+ async _prepareSuite ( suite ) {
448
462
const suiteName = suite . name ;
449
463
const suitePrepareStartLabel = `suite-${ suiteName } -prepare-start` ;
450
464
const suitePrepareEndLabel = `suite-${ suiteName } -prepare-end` ;
451
- const suiteStartLabel = `suite-${ suiteName } -start` ;
452
- const suiteEndLabel = `suite-${ suiteName } -end` ;
453
465
454
466
performance . mark ( suitePrepareStartLabel ) ;
455
- await this . _prepareSuite ( suite ) ;
467
+ await this . _loadFrame ( suite ) ;
468
+ await suite . prepare ( this . _page ) ;
456
469
performance . mark ( suitePrepareEndLabel ) ;
457
470
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
+
458
479
performance . mark ( suiteStartLabel ) ;
459
480
for ( const test of suite . tests )
460
481
await this . _runTestAndRecordResults ( suite , test ) ;
461
482
performance . mark ( suiteEndLabel ) ;
462
483
463
- performance . measure ( `suite-${ suiteName } -prepare` , suitePrepareStartLabel , suitePrepareEndLabel ) ;
464
484
performance . measure ( `suite-${ suiteName } ` , suiteStartLabel , suiteEndLabel ) ;
465
485
this . _validateSuiteTotal ( suiteName ) ;
466
486
}
@@ -474,14 +494,12 @@ export class BenchmarkRunner {
474
494
throw new Error ( `Got invalid 0-time total for suite ${ suiteName } : ${ suiteTotal } ` ) ;
475
495
}
476
496
477
- async _prepareSuite ( suite ) {
478
- return new Promise ( ( resolve ) => {
497
+ async _loadFrame ( suite ) {
498
+ return new Promise ( ( resolve , reject ) => {
479
499
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 ;
485
503
} ) ;
486
504
}
487
505
0 commit comments