1
1
/* eslint no-console: 0 */
2
2
'use strict'
3
3
4
- const path = require ( 'path' )
5
- const puppeteer = require ( 'puppeteer' )
6
- const fs = require ( 'fs' )
7
- const Table = require ( 'cli-table2' )
8
- const _ = require ( 'lodash' )
9
- const glob = require ( 'glob' )
10
- const yargs = require ( 'yargs/yargs' )
11
-
12
- const serverUtils = require ( './utils/server.js' )
13
-
14
- const readFolderNames = ( searchDir ) => {
4
+ import path from 'path'
5
+ import puppeteer from 'puppeteer'
6
+ import playwright from 'playwright'
7
+ import fs from 'fs'
8
+ import Table from 'cli-table2'
9
+ import _ from 'lodash'
10
+ import glob from 'glob'
11
+ import yargs from 'yargs/yargs'
12
+
13
+ import {
14
+ capturePageStats ,
15
+ ProcessedFPSEntry ,
16
+ runServer ,
17
+ PageStatsResult ,
18
+ RenderResult ,
19
+ } from './utils/server'
20
+
21
+ const readFolderNames = ( searchDir : string ) => {
15
22
return glob . sync ( '*/' , { cwd : searchDir } ) . map ( ( s ) => s . replace ( '/' , '' ) )
16
23
}
17
24
@@ -51,26 +58,27 @@ const args = yargs(process.argv.slice(2))
51
58
52
59
// Given an array of items such as ["a", "b", "c", "d"], return the pairwise entries
53
60
// in the form [ ["a","b"], ["b","c"], ["c","d"] ]
54
- function pairwise ( list ) {
61
+ function pairwise < T > ( list : T [ ] ) : [ T , T ] [ ] {
55
62
// Create a new list offset by 1
56
- var allButFirst = _ . rest ( list )
63
+ // @ts -ignore
64
+ const allButFirst : T [ ] = _ . rest ( list )
57
65
// Pair up entries at each index
58
- var zipped = _ . zip ( list , allButFirst )
66
+ const zipped = _ . zip ( list , allButFirst )
59
67
// Remove last entry, as there's a mismatch from the offset
60
- var pairwiseEntries = _ . initial ( zipped )
68
+ const pairwiseEntries = _ . initial ( zipped ) as [ T , T ] [ ]
61
69
return pairwiseEntries
62
70
}
63
71
64
72
function printBenchmarkResults ( benchmark , versionPerfEntries , trace ) {
65
73
console . log ( `\nResults for benchmark ${ benchmark } :` )
66
74
67
- let traceCategories = [ ]
75
+ let traceCategories : string [ ] = [ ]
68
76
69
77
if ( trace ) {
70
78
traceCategories = [ 'Scripting' , 'Rendering' , 'Painting' ]
71
79
}
72
80
73
- const table = new Table ( {
81
+ const table : any = new Table ( {
74
82
head : [
75
83
'Version' ,
76
84
'Avg FPS' ,
@@ -87,7 +95,7 @@ function printBenchmarkResults(benchmark, versionPerfEntries, trace) {
87
95
88
96
const { fps, profile, mountTime, averageUpdateTime } = versionResults
89
97
90
- let traceResults = [ ]
98
+ let traceResults : number [ ] = [ ]
91
99
92
100
if ( trace ) {
93
101
traceResults = [
@@ -112,10 +120,15 @@ function printBenchmarkResults(benchmark, versionPerfEntries, trace) {
112
120
}
113
121
114
122
function calculateBenchmarkStats (
115
- fpsRunResults ,
116
- categories ,
123
+ fpsRunResults : {
124
+ fpsValues : ProcessedFPSEntry [ ]
125
+ start : number
126
+ end : number
127
+ reactTimingEntries : RenderResult [ ]
128
+ } ,
129
+ categories : string [ ] ,
117
130
traceRunResults ,
118
- trace
131
+ trace : boolean
119
132
) {
120
133
const { fpsValues, start, end } = fpsRunResults
121
134
@@ -138,19 +151,24 @@ function calculateBenchmarkStats(
138
151
const duration = second . timestamp - first . timestamp
139
152
const durationSeconds = duration / 1000.0
140
153
141
- return { FPS : first . FPS , durationSeconds }
154
+ return { FPS : first . FPS , durationSeconds, weightedFPS : 0 }
142
155
} )
143
156
144
157
const sums = fpsValuesWithDurations . reduce (
145
158
( prev , current ) => {
146
159
const weightedFPS = current . FPS * current . durationSeconds
147
160
148
161
return {
162
+ FPS : current . FPS ,
149
163
weightedFPS : prev . weightedFPS + weightedFPS ,
150
164
durationSeconds : prev . durationSeconds + current . durationSeconds ,
151
165
}
152
166
} ,
153
- { FPS : 0 , weightedFPS : 0 , durationSeconds : 0 }
167
+ { FPS : 0 , weightedFPS : 0 , durationSeconds : 0 } as {
168
+ FPS : number
169
+ weightedFPS : number
170
+ durationSeconds : number
171
+ }
154
172
)
155
173
156
174
const weightedFPS = sums . weightedFPS / sums . durationSeconds
@@ -170,10 +188,20 @@ function calculateBenchmarkStats(
170
188
return { fps, profile : { categories } , mountTime, averageUpdateTime }
171
189
}
172
190
173
- async function runBenchmarks ( { scenarios, versions, length, trace } ) {
191
+ async function runBenchmarks ( {
192
+ scenarios,
193
+ versions,
194
+ length,
195
+ trace,
196
+ } : {
197
+ scenarios : string [ ]
198
+ versions : string [ ]
199
+ length : number
200
+ trace : boolean
201
+ } ) {
174
202
console . log ( 'Scenarios: ' , scenarios )
175
203
const distFolder = path . resolve ( 'dist' )
176
- const server = await serverUtils . runServer ( 9999 , distFolder )
204
+ const server = await runServer ( 9999 , distFolder )
177
205
178
206
for ( let scenario of scenarios ) {
179
207
const versionPerfEntries = { }
@@ -182,8 +210,8 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
182
210
183
211
for ( let version of versions ) {
184
212
console . log ( ` React-Redux version: ${ version } ` )
185
- const browser = await puppeteer . launch ( {
186
- // headless: false
213
+ const browser = await playwright . chromium . launch ( {
214
+ headless : true ,
187
215
} )
188
216
189
217
const folderPath = path . join ( distFolder , version , scenario )
@@ -198,14 +226,15 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
198
226
const URL = `http://localhost:9999/${ version } /${ scenario } `
199
227
try {
200
228
console . log ( ` Checking max FPS... (${ length } seconds)` )
201
- const fpsRunResults = await serverUtils . capturePageStats (
229
+ const fpsRunResults = await capturePageStats (
202
230
browser ,
203
231
URL ,
204
232
null ,
205
233
length * 1000
206
234
)
207
235
208
- let traceRunResults , categories
236
+ let traceRunResults : PageStatsResult | undefined
237
+ let categories : string [ ] = [ ]
209
238
210
239
if ( trace ) {
211
240
console . log ( ` Running trace... (${ length } seconds)` )
@@ -214,7 +243,7 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
214
243
'runs' ,
215
244
`trace-${ scenario } -${ version } .json`
216
245
)
217
- traceRunResults = await serverUtils . capturePageStats (
246
+ traceRunResults = await capturePageStats (
218
247
browser ,
219
248
URL ,
220
249
traceFilename ,
@@ -242,4 +271,5 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
242
271
process . exit ( 0 )
243
272
}
244
273
274
+ // @ts -ignore
245
275
runBenchmarks ( args . argv )
0 commit comments