33const child_process = require ( 'child_process' ) ;
44const http_benchmarkers = require ( './_http-benchmarkers.js' ) ;
55
6+ function allow ( ) {
7+ return true ;
8+ }
9+
610class Benchmark {
711 constructor ( fn , configs , options = { } ) {
812 // Used to make sure a benchmark only start a timer once
@@ -31,9 +35,17 @@ class Benchmark {
3135 this . flags = this . flags . concat ( options . flags ) ;
3236 }
3337
38+ if ( typeof options . combinationFilter === 'function' )
39+ this . combinationFilter = options . combinationFilter ;
40+ else
41+ this . combinationFilter = allow ;
42+
3443 // The configuration list as a queue of jobs
3544 this . queue = this . _queue ( this . options ) ;
3645
46+ if ( this . queue . length === 0 )
47+ return ;
48+
3749 // The configuration of the current job, head of the queue
3850 this . config = this . queue [ 0 ] ;
3951
@@ -108,6 +120,7 @@ class Benchmark {
108120 _queue ( options ) {
109121 const queue = [ ] ;
110122 const keys = Object . keys ( options ) ;
123+ const { combinationFilter } = this ;
111124
112125 // Perform a depth-first walk through all options to generate a
113126 // configuration list that contains all combinations.
@@ -131,7 +144,15 @@ class Benchmark {
131144 if ( keyIndex + 1 < keys . length ) {
132145 recursive ( keyIndex + 1 , currConfig ) ;
133146 } else {
134- queue . push ( currConfig ) ;
147+ // Check if we should allow the current combination
148+ const allowed = combinationFilter ( { ...currConfig } ) ;
149+ if ( typeof allowed !== 'boolean' ) {
150+ throw new TypeError (
151+ 'Combination filter must always return a boolean'
152+ ) ;
153+ }
154+ if ( allowed )
155+ queue . push ( currConfig ) ;
135156 }
136157 }
137158 }
0 commit comments