Skip to content

Commit

Permalink
benchmark: make benchmarks runnable in older versions of Node.js
Browse files Browse the repository at this point in the history
Also remove the require-cachable.js benchmarks because now all builtin
modules are cacheable, it would be comparing oranges to apples when
we try to compare the performance of loading all cacheable modules
in different Node.js binaries since the set of modules are just
different. Comparison of startup performance that involves loading
of the long-standing, stable builtins is already covered by the
require-builtins benchmark.
  • Loading branch information
joyeecheung committed Dec 5, 2022
1 parent 1287530 commit 996719f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
8 changes: 4 additions & 4 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Benchmark {
this.config = this.queue[0];

process.nextTick(() => {
if (Object.hasOwn(process.env, 'NODE_RUN_BENCHMARK_FN')) {
if (process.env.NODE_RUN_BENCHMARK_FN !== undefined) {
fn(this.config);
} else {
// _run will use fork() to create a new process for each configuration
Expand Down Expand Up @@ -91,7 +91,7 @@ class Benchmark {
process.exit(1);
}
const [, key, value] = match;
if (Object.hasOwn(configs, key)) {
if (configs[key] !== undefined) {
if (!cliOptions[key])
cliOptions[key] = [];
cliOptions[key].push(
Expand Down Expand Up @@ -290,10 +290,10 @@ function sendResult(data) {
if (process.send) {
// If forked, report by process send
process.send(data, () => {
if (Object.hasOwn(process.env, 'NODE_RUN_BENCHMARK_FN')) {
if (process.env.NODE_RUN_BENCHMARK_FN !== undefined) {
// If, for any reason, the process is unable to self close within
// a second after completing, forcefully close it.
setTimeout(() => {
require('timers').setTimeout(() => {
process.exit(0);
}, 5000).unref();
}
Expand Down
10 changes: 0 additions & 10 deletions benchmark/fixtures/require-cachable.js

This file was deleted.

2 changes: 1 addition & 1 deletion benchmark/misc/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function main({ dur, script, mode }) {
throughput: 0
};

setTimeout(() => {
require('timers').setTimeout(() => {
state.go = false;
}, dur * 1000);

Expand Down

0 comments on commit 996719f

Please sign in to comment.