| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e2698c0 commit 6186b3e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,10 @@ | |||
| 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 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -450,8 +450,12 @@ The arguments of `createBenchmark` are: | |||
| 450 | 450 | possible combinations of these parameters, unless specified otherwise. | |
| 451 | 451 | Each configuration is a property with an array of possible values. | |
| 452 | 452 | The configuration values can only be strings or numbers. | |
| 453 | - * `options` {Object} The benchmark options. At the moment only the `flags` | ||
| 454 | - option for specifying command line flags is supported. | ||
| 453 | + * `options` {Object} The benchmark options. Supported options: | ||
| 454 | + * `flags` {Array} Contains node-specific command line flags to pass to | ||
| 455 | + the child process. | ||
| 456 | + * `combinationFilter` {Function} Has a single parameter which is an object | ||
| 457 | + containing a combination of benchmark parameters. It should return `true` | ||
| 458 | + or `false` to indicate whether the combination should be included or not. | ||
| 455 | 459 | ||
| 456 | 460 | `createBenchmark` returns a `bench` object, which is used for timing | |
| 457 | 461 | the runtime of the benchmark. Run `bench.start()` after the initialization | |
| Back | FazBrowse Home | New Git URL |
0 commit comments