@@ -9,6 +9,8 @@ import sirv from 'sirv'
9
9
import { launch } from 'puppeteer'
10
10
import colors from 'picocolors'
11
11
import { exec , getSha } from '../scripts/utils.js'
12
+ import process from 'node:process'
13
+ import readline from 'node:readline'
12
14
13
15
// Thanks to https://github.com/krausest/js-framework-benchmark (Apache-2.0 license)
14
16
const {
@@ -20,6 +22,7 @@ const {
20
22
noVapor,
21
23
port : portStr ,
22
24
count : countStr ,
25
+ warmupCount : warmupCountStr ,
23
26
noHeadless,
24
27
devBuild,
25
28
} ,
@@ -56,6 +59,11 @@ const {
56
59
short : 'c' ,
57
60
default : '30' ,
58
61
} ,
62
+ warmupCount : {
63
+ type : 'string' ,
64
+ short : 'w' ,
65
+ default : '5' ,
66
+ } ,
59
67
noHeadless : {
60
68
type : 'boolean' ,
61
69
} ,
@@ -68,6 +76,7 @@ const {
68
76
69
77
const port = + ( /** @type {string }*/ ( portStr ) )
70
78
const count = + ( /** @type {string }*/ ( countStr ) )
79
+ const warmupCount = + ( /** @type {string }*/ ( warmupCountStr ) )
71
80
const sha = await getSha ( true )
72
81
73
82
if ( ! skipLib ) {
@@ -226,22 +235,11 @@ async function doBench(browser, isVapor) {
226
235
await forceGC ( )
227
236
const t = performance . now ( )
228
237
229
- for ( let i = 0 ; i < count ; i ++ ) {
230
- await clickButton ( 'run' ) // test: create rows
231
- await clickButton ( 'update' ) // partial update
232
- await clickButton ( 'swaprows' ) // swap rows
233
- await select ( ) // test: select row, remove row
234
- await clickButton ( 'clear' ) // clear rows
238
+ console . log ( 'warmup run' )
239
+ await eachRun ( ( ) => withoutRecord ( benchOnce ) , warmupCount )
235
240
236
- await withoutRecord ( ( ) => clickButton ( 'run' ) )
237
- await clickButton ( 'add' ) // append rows to large table
238
-
239
- await withoutRecord ( ( ) => clickButton ( 'clear' ) )
240
- await clickButton ( 'runLots' ) // create many rows
241
- await withoutRecord ( ( ) => clickButton ( 'clear' ) )
242
-
243
- // TODO replace all rows
244
- }
241
+ console . log ( 'benchmark run' )
242
+ await eachRun ( benchOnce , count )
245
243
246
244
console . info (
247
245
'Total time:' ,
@@ -261,6 +259,23 @@ async function doBench(browser, isVapor) {
261
259
await page . close ( )
262
260
return result
263
261
262
+ async function benchOnce ( ) {
263
+ await clickButton ( 'run' ) // test: create rows
264
+ await clickButton ( 'update' ) // partial update
265
+ await clickButton ( 'swaprows' ) // swap rows
266
+ await select ( ) // test: select row, remove row
267
+ await clickButton ( 'clear' ) // clear rows
268
+
269
+ await withoutRecord ( ( ) => clickButton ( 'run' ) )
270
+ await clickButton ( 'add' ) // append rows to large table
271
+
272
+ await withoutRecord ( ( ) => clickButton ( 'clear' ) )
273
+ await clickButton ( 'runLots' ) // create many rows
274
+ await withoutRecord ( ( ) => clickButton ( 'clear' ) )
275
+
276
+ // TODO replace all rows
277
+ }
278
+
264
279
function getTimes ( ) {
265
280
return page . evaluate ( ( ) => /** @type {any } */ ( globalThis ) . times )
266
281
}
@@ -273,9 +288,13 @@ async function doBench(browser, isVapor) {
273
288
274
289
/** @param {() => any } fn */
275
290
async function withoutRecord ( fn ) {
291
+ const currentRecordTime = await page . evaluate ( ( ) => globalThis . recordTime )
276
292
await page . evaluate ( ( ) => ( globalThis . recordTime = false ) )
277
293
await fn ( )
278
- await page . evaluate ( ( ) => ( globalThis . recordTime = true ) )
294
+ await page . evaluate (
295
+ currentRecordTime => ( globalThis . recordTime = currentRecordTime ) ,
296
+ currentRecordTime ,
297
+ )
279
298
}
280
299
281
300
/** @param {string } id */
@@ -298,6 +317,23 @@ async function doBench(browser, isVapor) {
298
317
}
299
318
}
300
319
320
+ /**
321
+ * @param {Function } bench
322
+ * @param {number } count
323
+ */
324
+ async function eachRun ( bench , count ) {
325
+ for ( let i = 0 ; i < count ; i ++ ) {
326
+ readline . cursorTo ( process . stdout , 0 )
327
+ readline . clearLine ( process . stdout , 0 )
328
+ process . stdout . write ( `${ i + 1 } /${ count } ` )
329
+ await bench ( )
330
+ }
331
+ if ( count === 0 ) {
332
+ process . stdout . write ( '0/0 (skip)' )
333
+ }
334
+ process . stdout . write ( '\n' )
335
+ }
336
+
301
337
async function initBrowser ( ) {
302
338
const disableFeatures = [
303
339
'Translate' , // avoid translation popups
0 commit comments