3
3
const child_process = require ( 'child_process' ) ;
4
4
const http_benchmarkers = require ( './_http-benchmarkers.js' ) ;
5
5
6
+ function allow ( ) {
7
+ return true ;
8
+ }
9
+
6
10
class Benchmark {
7
11
constructor ( fn , configs , options = { } ) {
8
12
// Used to make sure a benchmark only start a timer once
@@ -31,9 +35,17 @@ class Benchmark {
31
35
this . flags = this . flags . concat ( options . flags ) ;
32
36
}
33
37
38
+ if ( typeof options . combinationFilter === 'function' )
39
+ this . combinationFilter = options . combinationFilter ;
40
+ else
41
+ this . combinationFilter = allow ;
42
+
34
43
// The configuration list as a queue of jobs
35
44
this . queue = this . _queue ( this . options ) ;
36
45
46
+ if ( this . queue . length === 0 )
47
+ return ;
48
+
37
49
// The configuration of the current job, head of the queue
38
50
this . config = this . queue [ 0 ] ;
39
51
@@ -108,6 +120,7 @@ class Benchmark {
108
120
_queue ( options ) {
109
121
const queue = [ ] ;
110
122
const keys = Object . keys ( options ) ;
123
+ const { combinationFilter } = this ;
111
124
112
125
// Perform a depth-first walk through all options to generate a
113
126
// configuration list that contains all combinations.
@@ -131,7 +144,15 @@ class Benchmark {
131
144
if ( keyIndex + 1 < keys . length ) {
132
145
recursive ( keyIndex + 1 , currConfig ) ;
133
146
} 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 ) ;
135
156
}
136
157
}
137
158
}
0 commit comments