| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9b549c1 commit 76ebae4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,24 +4,24 @@ const child_process = require('child_process'); | |||
| 4 | 4 | const http_benchmarkers = require('./_http-benchmarkers.js'); | |
| 5 | 5 | ||
| 6 | 6 | class Benchmark { | |
| 7 | - // Used to make sure a benchmark only start a timer once | ||
| 8 | - #started = false; | ||
| 7 | + constructor(fn, configs, options = {}) { | ||
| 8 | + // Used to make sure a benchmark only start a timer once | ||
| 9 | + this._started = false; | ||
| 9 | 10 | ||
| 10 | - // Indicate that the benchmark ended | ||
| 11 | - #ended = false; | ||
| 11 | + // Indicate that the benchmark ended | ||
| 12 | + this._ended = false; | ||
| 12 | 13 | ||
| 13 | - // Holds process.hrtime value | ||
| 14 | - #time = [0, 0]; | ||
| 14 | + // Holds process.hrtime value | ||
| 15 | + this._time = [0, 0]; | ||
| 15 | 16 | ||
| 16 | - // Use the file name as the name of the benchmark | ||
| 17 | - name = require.main.filename.slice(__dirname.length + 1); | ||
| 17 | + // Use the file name as the name of the benchmark | ||
| 18 | + this.name = require.main.filename.slice(__dirname.length + 1); | ||
| 18 | 19 | ||
| 19 | - // Execution arguments i.e. flags used to run the jobs | ||
| 20 | - flags = process.env.NODE_BENCHMARK_FLAGS ? | ||
| 21 | - process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) : | ||
| 22 | - []; | ||
| 20 | + // Execution arguments i.e. flags used to run the jobs | ||
| 21 | + this.flags = process.env.NODE_BENCHMARK_FLAGS ? | ||
| 22 | + process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) : | ||
| 23 | + []; | ||
| 23 | 24 | ||
| 24 | - constructor(fn, configs, options = {}) { | ||
| 25 | 25 | // Parse job-specific configuration from the command line arguments | |
| 26 | 26 | const argv = process.argv.slice(2); | |
| 27 | 27 | const parsed_args = this._parseArgs(argv, configs, options); | |
@@ -214,21 +214,21 @@ class Benchmark { | |||
| 214 | 214 | } | |
| 215 | 215 | ||
| 216 | 216 | start() { | |
| 217 | - if (this.#started) { | ||
| 217 | + if (this._started) { | ||
| 218 | 218 | throw new Error('Called start more than once in a single benchmark'); | |
| 219 | 219 | } | |
| 220 | - this.#started = true; | ||
| 221 | - this.#time = process.hrtime(); | ||
| 220 | + this._started = true; | ||
| 221 | + this._time = process.hrtime(); | ||
| 222 | 222 | } | |
| 223 | 223 | ||
| 224 | 224 | end(operations) { | |
| 225 | 225 | // Get elapsed time now and do error checking later for accuracy. | |
| 226 | - const elapsed = process.hrtime(this.#time); | ||
| 226 | + const elapsed = process.hrtime(this._time); | ||
| 227 | 227 | ||
| 228 | - if (!this.#started) { | ||
| 228 | + if (!this._started) { | ||
| 229 | 229 | throw new Error('called end without start'); | |
| 230 | 230 | } | |
| 231 | - if (this.#ended) { | ||
| 231 | + if (this._ended) { | ||
| 232 | 232 | throw new Error('called end multiple times'); | |
| 233 | 233 | } | |
| 234 | 234 | if (typeof operations !== 'number') { | |
@@ -244,7 +244,7 @@ class Benchmark { | |||
| 244 | 244 | elapsed[1] = 1; | |
| 245 | 245 | } | |
| 246 | 246 | ||
| 247 | - this.#ended = true; | ||
| 247 | + this._ended = true; | ||
| 248 | 248 | const time = elapsed[0] + elapsed[1] / 1e9; | |
| 249 | 249 | const rate = operations / time; | |
| 250 | 250 | this.report(rate, elapsed); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments