@@ -39,14 +39,16 @@ class Benchmark {
3939 maxTime ;
4040 plugins ;
4141 repeatSuite ;
42+ minSamples ;
4243
43- constructor ( name , fn , minTime , maxTime , plugins , repeatSuite ) {
44+ constructor ( name , fn , minTime , maxTime , plugins , repeatSuite , minSamples ) {
4445 this . name = name ;
4546 this . fn = fn ;
4647 this . minTime = minTime ;
4748 this . maxTime = maxTime ;
4849 this . plugins = plugins ;
4950 this . repeatSuite = repeatSuite ;
51+ this . minSamples = minSamples ;
5052
5153 this . hasArg = this . fn . length >= 1 ;
5254 if ( this . fn . length > 1 ) {
@@ -75,6 +77,8 @@ const defaultBenchOptions = {
7577 maxTime : 0.5 ,
7678 // Number of times the benchmark will be repeated
7779 repeatSuite : 1 ,
80+ // Number minimum of samples the each round
81+ minSamples : 10 ,
7882} ;
7983
8084function throwIfNoNativesSyntax ( ) {
@@ -133,6 +137,11 @@ class Suite {
133137 "options.repeatSuite" ,
134138 options . repeatSuite ,
135139 ) ;
140+ validateNumber (
141+ options . minSamples ,
142+ "options.minSamples" ,
143+ options . minSamples ,
144+ ) ;
136145 }
137146 validateFunction ( fn , "fn" ) ;
138147
@@ -143,6 +152,7 @@ class Suite {
143152 options . maxTime ,
144153 this . #plugins,
145154 options . repeatSuite ,
155+ options . minSamples ,
146156 ) ;
147157 this . #benchmarks. push ( benchmark ) ;
148158 return this ;
@@ -174,7 +184,7 @@ class Suite {
174184 // Warmup is calculated to reduce noise/bias on the results
175185 const initialIterations = await getInitialIterations ( benchmark ) ;
176186 debugBench (
177- `Starting ${ benchmark . name } with minTime=${ benchmark . minTime } , maxTime=${ benchmark . maxTime } , repeatSuite=${ benchmark . repeatSuite } ` ,
187+ `Starting ${ benchmark . name } with minTime=${ benchmark . minTime } , maxTime=${ benchmark . maxTime } , repeatSuite=${ benchmark . repeatSuite } , minSamples= ${ benchmark . minSamples } ` ,
178188 ) ;
179189
180190 let result ;
@@ -185,6 +195,7 @@ class Suite {
185195 benchmark ,
186196 initialIterations ,
187197 benchmark . repeatSuite ,
198+ benchmark . minSamples ,
188199 ) ;
189200 }
190201 results [ i ] = result ;
@@ -204,6 +215,7 @@ class Suite {
204215 benchmark,
205216 initialIterations,
206217 repeatSuite : benchmark . repeatSuite ,
218+ minSamples : benchmark . minSamples ,
207219 } ) ;
208220 return new Promise ( ( resolve , reject ) => {
209221 worker . on ( "message" , ( result ) => {
0 commit comments