@@ -3,19 +3,22 @@ import * as fs from "fs";
3
3
import * as yargs from "yargs" ;
4
4
import { BenchmarkInfo , BenchmarkType } from "./benchmarksCommon" ;
5
5
import { BenchmarkPuppeteer } from "./benchmarksPuppeteer" ;
6
- import { BenchmarkWebdriver , LighthouseData } from "./benchmarksWebdriver" ;
7
- import { BenchmarkOptions , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common" ;
6
+ import { BenchmarkWebdriver } from "./benchmarksWebdriver" ;
7
+ import { BenchmarkDriverOptions , BenchmarkOptions , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common" ;
8
8
import { writeResults } from "./writeResults" ;
9
9
import { benchmarks } from "./benchmarkConfiguration" ;
10
+ import { BenchmarkLighthouse , StartupBenchmarkResult } from "./benchmarksLighthouse" ;
10
11
11
12
function forkAndCallBenchmark (
12
13
framework : FrameworkData ,
13
- benchmark : BenchmarkInfo ,
14
+ benchmark : BenchmarkWebdriver | BenchmarkLighthouse | BenchmarkPuppeteer ,
14
15
benchmarkOptions : BenchmarkOptions
15
16
) : Promise < ErrorAndWarning > {
16
17
return new Promise ( ( resolve , reject ) => {
17
18
let forkedRunner = null ;
18
- if ( benchmarks . some ( b => b . benchmarkInfo . id == benchmark . id && b instanceof BenchmarkPuppeteer ) ) {
19
+ if ( benchmark instanceof BenchmarkLighthouse ) {
20
+ forkedRunner = "dist/forkedBenchmarkRunnerLighthouse.js" ;
21
+ } else if ( benchmark instanceof BenchmarkPuppeteer ) {
19
22
forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js" ;
20
23
} else {
21
24
forkedRunner = "dist/forkedBenchmarkRunnerWebdriver.js" ;
@@ -46,6 +49,54 @@ function forkAndCallBenchmark(
46
49
} ) ;
47
50
}
48
51
52
+ async function runBenchmakLoopStartup (
53
+ framework : FrameworkData ,
54
+ benchmark : BenchmarkLighthouse ,
55
+ benchmarkOptions : BenchmarkOptions
56
+ ) : Promise < { errors : String [ ] ; warnings : String [ ] } > {
57
+ if ( config . FORK_CHROMEDRIVER ) {
58
+ let warnings : String [ ] = [ ] ;
59
+ let errors : String [ ] = [ ] ;
60
+
61
+ let results : Array < StartupBenchmarkResult > = [ ] ;
62
+ let count = benchmarkOptions . numIterationsForStartupBenchmark ;
63
+ benchmarkOptions . batchSize = 1 ;
64
+
65
+ let retries = 0 ;
66
+ let done = 0 ;
67
+
68
+ while ( done < count ) {
69
+ console . log ( "FORKING: " , benchmark . id , " BatchSize " , benchmarkOptions . batchSize ) ;
70
+ let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
71
+ if ( Array . isArray ( res . result ) ) {
72
+ results = results . concat ( res . result as StartupBenchmarkResult [ ] ) ;
73
+ } else results . push ( res . result ) ;
74
+ warnings = warnings . concat ( res . warnings ) ;
75
+ if ( res . error ) {
76
+ if ( res . error . indexOf ( "Server terminated early with status 1" ) > - 1 ) {
77
+ console . log ( "******* STRANGE selenium error found - retry #" , retries + 1 ) ;
78
+ retries ++ ;
79
+ if ( retries == 3 ) break ;
80
+ } else {
81
+ errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . id } failed: ` + res . error ) ;
82
+ break ;
83
+ }
84
+ }
85
+ done ++ ;
86
+ }
87
+ console . log ( "******* result " , results ) ;
88
+ await writeResults ( config , {
89
+ framework : framework ,
90
+ benchmark : benchmark ,
91
+ results : results ,
92
+ type : BenchmarkType . STARTUP
93
+ } ) ;
94
+ return { errors, warnings } ;
95
+ // } else {
96
+ // return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
97
+ }
98
+ }
99
+
49
100
async function runBenchmakLoop (
50
101
framework : FrameworkData ,
51
102
benchmark : BenchmarkWebdriver | BenchmarkPuppeteer ,
@@ -55,7 +106,7 @@ async function runBenchmakLoop(
55
106
let warnings : String [ ] = [ ] ;
56
107
let errors : String [ ] = [ ] ;
57
108
58
- let results : Array < number | LighthouseData > = [ ] ;
109
+ let results : Array < number > = [ ] ;
59
110
let count = 0 ;
60
111
61
112
if ( benchmark . type == BenchmarkType . CPU ) {
@@ -64,9 +115,6 @@ async function runBenchmakLoop(
64
115
} else if ( benchmark . type == BenchmarkType . MEM ) {
65
116
count = benchmarkOptions . numIterationsForMemBenchmarks ;
66
117
benchmarkOptions . batchSize = 1 ;
67
- } else {
68
- count = benchmarkOptions . numIterationsForStartupBenchmark ;
69
- benchmarkOptions . batchSize = 1 ;
70
118
}
71
119
72
120
let retries = 0 ;
@@ -75,11 +123,9 @@ async function runBenchmakLoop(
75
123
benchmarkOptions . batchSize = Math . min ( benchmarkOptions . batchSize , count - results . length ) ;
76
124
console . log ( "FORKING: " , benchmark . id , " BatchSize " , benchmarkOptions . batchSize ) ;
77
125
let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
78
- if ( res . result ) {
79
- if ( Array . isArray ( res . result ) ) {
80
- results = results . concat ( res . result ) ;
81
- } else results . push ( res . result ) ;
82
- }
126
+ if ( Array . isArray ( res . result ) ) {
127
+ results = results . concat ( res . result as number [ ] ) ;
128
+ } else results . push ( res . result ) ;
83
129
warnings = warnings . concat ( res . warnings ) ;
84
130
if ( res . error ) {
85
131
if ( res . error . indexOf ( "Server terminated early with status 1" ) > - 1 ) {
@@ -104,6 +150,7 @@ async function runBenchmakLoop(
104
150
framework : framework ,
105
151
benchmark : benchmark ,
106
152
results : results ,
153
+ type : benchmark . type as typeof BenchmarkType . CPU | BenchmarkType . MEM
107
154
} ) ;
108
155
return { errors, warnings } ;
109
156
// } else {
@@ -115,7 +162,7 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
115
162
let errors : String [ ] = [ ] ;
116
163
let warnings : String [ ] = [ ] ;
117
164
118
- let runBenchmarks : Array < BenchmarkWebdriver | BenchmarkPuppeteer > = benchmarks . filter ( ( b ) =>
165
+ let runBenchmarks : Array < BenchmarkWebdriver | BenchmarkPuppeteer | BenchmarkLighthouse > = benchmarks . filter ( ( b ) =>
119
166
benchmarkNames . some ( ( name ) => b . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
120
167
) ;
121
168
@@ -151,7 +198,9 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
151
198
for ( let i = 0 ; i < runFrameworks . length ; i ++ ) {
152
199
for ( let j = 0 ; j < runBenchmarks . length ; j ++ ) {
153
200
try {
154
- let result = await runBenchmakLoop ( runFrameworks [ i ] , runBenchmarks [ j ] , benchmarkOptions ) ;
201
+ let result = ( runBenchmarks [ j ] . type == BenchmarkType . STARTUP ) ?
202
+ await runBenchmakLoopStartup ( runFrameworks [ i ] , runBenchmarks [ j ] as BenchmarkLighthouse , benchmarkOptions )
203
+ : await runBenchmakLoop ( runFrameworks [ i ] , runBenchmarks [ j ] as BenchmarkPuppeteer | BenchmarkWebdriver , benchmarkOptions ) ;
155
204
errors = errors . concat ( result . errors ) ;
156
205
warnings = warnings . concat ( result . warnings ) ;
157
206
} catch ( e ) {
0 commit comments