@@ -2,23 +2,23 @@ import { fork } from "child_process";
2
2
import * as fs from "fs" ;
3
3
import * as yargs from "yargs" ;
4
4
import { BenchmarkInfo , BenchmarkType } from "./benchmarksCommon" ;
5
- import { BenchmarkPuppeteer } from "./benchmarksPuppeteer" ;
6
- import { BenchmarkWebdriver } from "./benchmarksWebdriver" ;
5
+ import { CPUBenchmarkPuppeteer , MemBenchmarkPuppeteer , TBenchmarkPuppeteer } from "./benchmarksPuppeteer" ;
6
+ import { CPUBenchmarkWebdriver } from "./benchmarksWebdriver" ;
7
7
import { BenchmarkDriverOptions , BenchmarkOptions , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common" ;
8
8
import { writeResults } from "./writeResults" ;
9
9
import { benchmarks } from "./benchmarkConfiguration" ;
10
10
import { BenchmarkLighthouse , StartupBenchmarkResult } from "./benchmarksLighthouse" ;
11
11
12
12
function forkAndCallBenchmark (
13
13
framework : FrameworkData ,
14
- benchmark : BenchmarkWebdriver | BenchmarkLighthouse | BenchmarkPuppeteer ,
14
+ benchmark : CPUBenchmarkWebdriver | TBenchmarkPuppeteer | BenchmarkLighthouse ,
15
15
benchmarkOptions : BenchmarkOptions
16
16
) : Promise < ErrorAndWarning > {
17
17
return new Promise ( ( resolve , reject ) => {
18
18
let forkedRunner = null ;
19
19
if ( benchmark instanceof BenchmarkLighthouse ) {
20
20
forkedRunner = "dist/forkedBenchmarkRunnerLighthouse.js" ;
21
- } else if ( benchmark instanceof BenchmarkPuppeteer ) {
21
+ } else if ( benchmark instanceof CPUBenchmarkPuppeteer || benchmark instanceof MemBenchmarkPuppeteer ) {
22
22
forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js" ;
23
23
} else {
24
24
forkedRunner = "dist/forkedBenchmarkRunnerWebdriver.js" ;
@@ -29,7 +29,7 @@ function forkAndCallBenchmark(
29
29
forked . send ( {
30
30
config,
31
31
framework,
32
- benchmarkId : benchmark . id ,
32
+ benchmarkId : benchmark . benchmarkInfo . id ,
33
33
benchmarkOptions,
34
34
} ) ;
35
35
forked . on ( "message" , async ( msg : ErrorAndWarning ) => {
@@ -54,116 +54,118 @@ async function runBenchmakLoopStartup(
54
54
benchmark : BenchmarkLighthouse ,
55
55
benchmarkOptions : BenchmarkOptions
56
56
) : Promise < { errors : String [ ] ; warnings : String [ ] } > {
57
- if ( config . FORK_CHROMEDRIVER ) {
58
- let warnings : String [ ] = [ ] ;
59
- let errors : String [ ] = [ ] ;
57
+ let warnings : String [ ] = [ ] ;
58
+ let errors : String [ ] = [ ] ;
59
+
60
+ let results : Array < StartupBenchmarkResult > = [ ] ;
61
+ let count = benchmarkOptions . numIterationsForStartupBenchmark ;
62
+ benchmarkOptions . batchSize = 1 ;
63
+
64
+ let retries = 0 ;
65
+ let done = 0 ;
66
+
67
+ console . log ( "runBenchmakLoopStartup" , framework , benchmark ) ;
60
68
61
- let results : Array < StartupBenchmarkResult > = [ ] ;
62
- let count = benchmarkOptions . numIterationsForStartupBenchmark ;
63
- benchmarkOptions . batchSize = 1 ;
64
69
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
- }
70
+ while ( done < count ) {
71
+ console . log ( "FORKING: " , benchmark . benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
72
+ let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
73
+ if ( Array . isArray ( res . result ) ) {
74
+ results = results . concat ( res . result as StartupBenchmarkResult [ ] ) ;
75
+ } else results . push ( res . result ) ;
76
+ warnings = warnings . concat ( res . warnings ) ;
77
+ if ( res . error ) {
78
+ if ( res . error . indexOf ( "Server terminated early with status 1" ) > - 1 ) {
79
+ console . log ( "******* STRANGE selenium error found - retry #" , retries + 1 ) ;
80
+ retries ++ ;
81
+ if ( retries == 3 ) break ;
82
+ } else {
83
+ errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . benchmarkInfo . id } failed: ` + res . error ) ;
84
+ break ;
84
85
}
85
- done ++ ;
86
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);
87
+ done ++ ;
97
88
}
89
+ console . log ( "******* result " , results ) ;
90
+ await writeResults ( config , {
91
+ framework : framework ,
92
+ benchmark : benchmark ,
93
+ results : results ,
94
+ type : BenchmarkType . STARTUP
95
+ } ) ;
96
+ return { errors, warnings } ;
97
+ // } else {
98
+ // return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
98
99
}
99
100
100
101
async function runBenchmakLoop (
101
102
framework : FrameworkData ,
102
- benchmark : BenchmarkWebdriver | BenchmarkPuppeteer ,
103
+ benchmark : CPUBenchmarkWebdriver | TBenchmarkPuppeteer ,
103
104
benchmarkOptions : BenchmarkOptions
104
105
) : Promise < { errors : String [ ] ; warnings : String [ ] } > {
105
- if ( config . FORK_CHROMEDRIVER ) {
106
- let warnings : String [ ] = [ ] ;
107
- let errors : String [ ] = [ ] ;
108
-
109
- let results : Array < number > = [ ] ;
110
- let count = 0 ;
111
-
112
- if ( benchmark . type == BenchmarkType . CPU ) {
113
- count = benchmarkOptions . numIterationsForCPUBenchmarks ;
114
- benchmarkOptions . batchSize = config . ALLOW_BATCHING && benchmark . allowBatching ? count : 1 ;
115
- } else if ( benchmark . type == BenchmarkType . MEM ) {
116
- count = benchmarkOptions . numIterationsForMemBenchmarks ;
117
- benchmarkOptions . batchSize = 1 ;
118
- }
106
+ let warnings : String [ ] = [ ] ;
107
+ let errors : String [ ] = [ ] ;
108
+
109
+ let results : Array < number > = [ ] ;
110
+ let count = 0 ;
119
111
120
- let retries = 0 ;
121
-
122
- while ( results . length < count ) {
123
- benchmarkOptions . batchSize = Math . min ( benchmarkOptions . batchSize , count - results . length ) ;
124
- console . log ( "FORKING: " , benchmark . id , " BatchSize " , benchmarkOptions . batchSize ) ;
125
- let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
126
- if ( Array . isArray ( res . result ) ) {
127
- results = results . concat ( res . result as number [ ] ) ;
128
- } else results . push ( res . result ) ;
129
- warnings = warnings . concat ( res . warnings ) ;
130
- if ( res . error ) {
131
- if ( res . error . indexOf ( "Server terminated early with status 1" ) > - 1 ) {
132
- console . log ( "******* STRANGE selenium error found - retry #" , retries + 1 ) ;
133
- retries ++ ;
134
- if ( retries == 3 ) break ;
135
- } else {
136
- errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . id } failed: ` + res . error ) ;
137
- break ;
138
- }
112
+ if ( benchmark . type == BenchmarkType . CPU ) {
113
+ count = benchmarkOptions . numIterationsForCPUBenchmarks ;
114
+ // FIXME
115
+ benchmarkOptions . batchSize = config . ALLOW_BATCHING && ( benchmark . benchmarkInfo as any ) . allowBatching ? count : 1 ;
116
+ } else if ( benchmark . type == BenchmarkType . MEM ) {
117
+ count = benchmarkOptions . numIterationsForMemBenchmarks ;
118
+ benchmarkOptions . batchSize = 1 ;
119
+ }
120
+
121
+ let retries = 0 ;
122
+
123
+ console . log ( "runBenchmakLoop" , framework , benchmark ) ;
124
+
125
+ while ( results . length < count ) {
126
+ benchmarkOptions . batchSize = Math . min ( benchmarkOptions . batchSize , count - results . length ) ;
127
+ console . log ( "FORKING: " , benchmark . benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
128
+ let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
129
+ if ( Array . isArray ( res . result ) ) {
130
+ results = results . concat ( res . result as number [ ] ) ;
131
+ } else results . push ( res . result ) ;
132
+ warnings = warnings . concat ( res . warnings ) ;
133
+ if ( res . error ) {
134
+ if ( res . error . indexOf ( "Server terminated early with status 1" ) > - 1 ) {
135
+ console . log ( "******* STRANGE selenium error found - retry #" , retries + 1 ) ;
136
+ retries ++ ;
137
+ if ( retries == 3 ) break ;
138
+ } else {
139
+ errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . benchmarkInfo . id } failed: ` + res . error ) ;
140
+ break ;
139
141
}
140
142
}
141
- if ( benchmark . type == BenchmarkType . CPU ) {
142
- console . log ( "CPU results before: " , results ) ;
143
- ( results as number [ ] ) . sort ( ( a : number , b : number ) => a - b ) ;
144
- results = results . slice ( 0 , config . NUM_ITERATIONS_FOR_BENCHMARK_CPU ) ;
145
- // console.log("CPU results after: ", results)
146
- }
147
-
148
- console . log ( "******* result " , results ) ;
149
- await writeResults ( config , {
150
- framework : framework ,
151
- benchmark : benchmark ,
152
- results : results ,
153
- type : benchmark . type as typeof BenchmarkType . CPU | BenchmarkType . MEM
154
- } ) ;
155
- return { errors, warnings } ;
156
- // } else {
157
- // return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
158
143
}
144
+ if ( benchmark . type == BenchmarkType . CPU ) {
145
+ console . log ( "CPU results before: " , results ) ;
146
+ ( results as number [ ] ) . sort ( ( a : number , b : number ) => a - b ) ;
147
+ results = results . slice ( 0 , config . NUM_ITERATIONS_FOR_BENCHMARK_CPU ) ;
148
+ // console.log("CPU results after: ", results)
149
+ }
150
+
151
+ console . log ( "******* result " , results ) ;
152
+ await writeResults ( config , {
153
+ framework : framework ,
154
+ benchmark : benchmark . benchmarkInfo ,
155
+ results : results ,
156
+ type : benchmark . type as typeof BenchmarkType . CPU | BenchmarkType . MEM
157
+ } ) ;
158
+ return { errors, warnings } ;
159
+ // } else {
160
+ // return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
159
161
}
160
162
161
163
async function runBench ( runFrameworks : FrameworkData [ ] , benchmarkNames : string [ ] ) {
162
164
let errors : String [ ] = [ ] ;
163
165
let warnings : String [ ] = [ ] ;
164
166
165
- let runBenchmarks : Array < BenchmarkWebdriver | BenchmarkPuppeteer | BenchmarkLighthouse > = benchmarks . filter ( ( b ) =>
166
- benchmarkNames . some ( ( name ) => b . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
167
+ let runBenchmarks : Array < CPUBenchmarkWebdriver | TBenchmarkPuppeteer | BenchmarkLighthouse > = benchmarks . filter ( ( b ) =>
168
+ benchmarkNames . some ( ( name ) => b . benchmarkInfo . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
167
169
) ;
168
170
169
171
let restart : string = undefined ;
@@ -178,7 +180,7 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
178
180
) ;
179
181
console . log (
180
182
"Benchmarks that will be run" ,
181
- runBenchmarks . map ( ( b ) => b . id )
183
+ runBenchmarks . map ( ( b ) => b . benchmarkInfo . id )
182
184
) ;
183
185
184
186
console . log ( "HEADLESS*** " , args . headless ) ;
@@ -198,9 +200,10 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
198
200
for ( let i = 0 ; i < runFrameworks . length ; i ++ ) {
199
201
for ( let j = 0 ; j < runBenchmarks . length ; j ++ ) {
200
202
try {
201
- let result = ( runBenchmarks [ j ] . type == BenchmarkType . STARTUP ) ?
203
+ console . log ( "****** runBenchmarks[j].type" , runBenchmarks [ j ] . type , runBenchmarks [ j ] . type == BenchmarkType . STARTUP_MAIN )
204
+ let result = ( runBenchmarks [ j ] . type == BenchmarkType . STARTUP_MAIN ) ?
202
205
await runBenchmakLoopStartup ( runFrameworks [ i ] , runBenchmarks [ j ] as BenchmarkLighthouse , benchmarkOptions )
203
- : await runBenchmakLoop ( runFrameworks [ i ] , runBenchmarks [ j ] as BenchmarkPuppeteer | BenchmarkWebdriver , benchmarkOptions ) ;
206
+ : await runBenchmakLoop ( runFrameworks [ i ] , runBenchmarks [ j ] as TBenchmarkPuppeteer | CPUBenchmarkWebdriver , benchmarkOptions ) ;
204
207
errors = errors . concat ( result . errors ) ;
205
208
warnings = warnings . concat ( result . warnings ) ;
206
209
} catch ( e ) {
0 commit comments