@@ -14,22 +14,61 @@ async function run() {
1414 await initWasm ( fs . readFile ( join ( __dirname , "../wasm/index_bg.wasm" ) ) ) ;
1515
1616 for ( const { name, html } of benches ) {
17+ // Use more samples for big_page benchmark to get better resolution
18+ const options = name === "big_page" ? { minSamples : 20 } : { } ;
1719 await b . suite (
1820 name ,
19- b . add ( "css-inline" , ( ) => {
20- inline ( html ) ;
21- } ) ,
22- b . add ( "css-inline-wasm" , ( ) => {
23- wasmInline ( html ) ;
24- } ) ,
25- b . add ( "juice" , ( ) => {
26- juice ( html ) ;
27- } ) ,
28- b . add ( "inline-css" , ( ) => {
29- inlineCss ( html ) ;
30- } ) ,
21+ b . add (
22+ "css-inline" ,
23+ ( ) => {
24+ inline ( html ) ;
25+ } ,
26+ options ,
27+ ) ,
28+ b . add (
29+ "css-inline-wasm" ,
30+ ( ) => {
31+ wasmInline ( html ) ;
32+ } ,
33+ options ,
34+ ) ,
35+ b . add (
36+ "juice" ,
37+ ( ) => {
38+ juice ( html ) ;
39+ } ,
40+ options ,
41+ ) ,
42+ b . add (
43+ "inline-css" ,
44+ ( ) => {
45+ inlineCss ( html ) ;
46+ } ,
47+ options ,
48+ ) ,
3149 b . cycle ( ) ,
32- b . complete ( ) ,
50+ b . complete ( ( summary ) => {
51+ // For slow benchmarks, print precise timing from mean values
52+ const fastest = summary . results [ 0 ] ;
53+ if ( fastest . ops < 100 ) {
54+ // eslint-disable-next-line no-console
55+ console . log ( "\nPrecise timing (mean):" ) ;
56+ const fastestMean = fastest . details . mean ;
57+ for ( const result of summary . results ) {
58+ const mean = result . details . mean ;
59+ const timeStr =
60+ mean >= 1
61+ ? `${ mean . toFixed ( 2 ) } s`
62+ : `${ ( mean * 1000 ) . toFixed ( 2 ) } ms` ;
63+ const ratio =
64+ result === fastest
65+ ? ""
66+ : ` (${ ( mean / fastestMean ) . toFixed ( 2 ) } x slower)` ;
67+ // eslint-disable-next-line no-console
68+ console . log ( ` ${ result . name } : ${ timeStr } ${ ratio } ` ) ;
69+ }
70+ }
71+ } ) ,
3372 ) ;
3473 }
3574}
0 commit comments