MCPcopy Index your code
hub / github.com/nodejs/node / constructor

Method constructor

benchmark/common.js:11–71  ·  view source on GitHub ↗
(fn, configs, options = {})

Source from the content-addressed store, hash-verified

9
10class Benchmark {
11 constructor(fn, configs, options = {}) {
12 // Used to make sure a benchmark only start a timer once
13 this._started = false;
14
15 // Indicate that the benchmark ended
16 this._ended = false;
17
18 // Holds process.hrtime value
19 this._time = 0n;
20
21 // Use the file name as the name of the benchmark
22 this.name = require.main.filename.slice(__dirname.length + 1);
23
24 // Execution arguments i.e. flags used to run the jobs
25 this.flags = process.env.NODE_BENCHMARK_FLAGS?.split(/\s+/) ?? [];
26
27 // Parse job-specific configuration from the command line arguments
28 const argv = process.argv.slice(2);
29 const parsed_args = this._parseArgs(argv, configs, options);
30
31 this.originalOptions = options;
32 this.options = parsed_args.cli;
33 this.extra_options = parsed_args.extra;
34 this.combinationFilter = typeof options.combinationFilter === 'function' ? options.combinationFilter : allow;
35
36 if (options.byGroups) {
37 this.queue = [];
38 const groupNames = process.env.NODE_RUN_BENCHMARK_GROUPS?.split(',') ?? Object.keys(configs);
39
40 for (const groupName of groupNames) {
41 const config = { ...configs[groupName][0], group: groupName };
42 const parsed_args = this._parseArgs(argv, config, options);
43
44 this.options = parsed_args.cli;
45 this.extra_options = parsed_args.extra;
46 this.queue = this.queue.concat(this._queue(this.options));
47 }
48 } else {
49 this.queue = this._queue(this.options);
50 }
51
52 if (options.flags) {
53 this.flags = this.flags.concat(options.flags);
54 }
55
56 if (this.queue.length === 0)
57 return;
58
59 // The configuration of the current job, head of the queue
60 this.config = this.queue[0];
61
62 process.nextTick(() => {
63 if (process.env.NODE_RUN_BENCHMARK_FN !== undefined) {
64 fn(this.config);
65 } else {
66 // _run will use fork() to create a new process for each configuration
67 // combination.
68 this._run();

Callers

nothing calls this directly

Calls 8

_parseArgsMethod · 0.95
_queueMethod · 0.95
_runMethod · 0.95
concatMethod · 0.80
sliceMethod · 0.65
keysMethod · 0.65
fnFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected