@@ -9,6 +9,8 @@ import sirv from 'sirv'
99import { launch } from 'puppeteer'
1010import colors from 'picocolors'
1111import { exec , getSha } from '../scripts/utils.js'
12+ import process from 'node:process'
13+ import readline from 'node:readline'
1214
1315// Thanks to https://github.com/krausest/js-framework-benchmark (Apache-2.0 license)
1416const {
@@ -20,6 +22,7 @@ const {
2022 noVapor,
2123 port : portStr ,
2224 count : countStr ,
25+ warmupCount : warmupCountStr ,
2326 noHeadless,
2427 devBuild,
2528 } ,
@@ -56,6 +59,11 @@ const {
5659 short : 'c' ,
5760 default : '30' ,
5861 } ,
62+ warmupCount : {
63+ type : 'string' ,
64+ short : 'w' ,
65+ default : '5' ,
66+ } ,
5967 noHeadless : {
6068 type : 'boolean' ,
6169 } ,
@@ -68,6 +76,7 @@ const {
6876
6977const port = + ( /** @type {string }*/ ( portStr ) )
7078const count = + ( /** @type {string }*/ ( countStr ) )
79+ const warmupCount = + ( /** @type {string }*/ ( warmupCountStr ) )
7180const sha = await getSha ( true )
7281
7382if ( ! skipLib ) {
@@ -226,22 +235,11 @@ async function doBench(browser, isVapor) {
226235 await forceGC ( )
227236 const t = performance . now ( )
228237
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 )
235240
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 )
245243
246244 console . info (
247245 'Total time:' ,
@@ -261,6 +259,23 @@ async function doBench(browser, isVapor) {
261259 await page . close ( )
262260 return result
263261
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+
264279 function getTimes ( ) {
265280 return page . evaluate ( ( ) => /** @type {any } */ ( globalThis ) . times )
266281 }
@@ -273,9 +288,13 @@ async function doBench(browser, isVapor) {
273288
274289 /** @param {() => any } fn */
275290 async function withoutRecord ( fn ) {
291+ const currentRecordTime = await page . evaluate ( ( ) => globalThis . recordTime )
276292 await page . evaluate ( ( ) => ( globalThis . recordTime = false ) )
277293 await fn ( )
278- await page . evaluate ( ( ) => ( globalThis . recordTime = true ) )
294+ await page . evaluate (
295+ currentRecordTime => ( globalThis . recordTime = currentRecordTime ) ,
296+ currentRecordTime ,
297+ )
279298 }
280299
281300 /** @param {string } id */
@@ -298,6 +317,23 @@ async function doBench(browser, isVapor) {
298317 }
299318}
300319
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+
301337async function initBrowser ( ) {
302338 const disableFeatures = [
303339 'Translate' , // avoid translation popups
0 commit comments