Skip to content

Commit 3b626d2

Browse files
committed
test: improve performance of test-crypto-timing-safe-equal-benchmarks
Resetting require.cache() to `Object.create(null)` each time rather than deleting the specific key results in a 10x improvement in running time. Fixes: nodejs#25984 Refs: nodejs#26229
1 parent d1011f6 commit 3b626d2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/pummel/test-crypto-timing-safe-equal-benchmarks.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ function runOneBenchmark(...args) {
1818

1919
// Don't let the comparison function get cached. This avoid a timing
2020
// inconsistency due to V8 optimization where the function would take
21-
// less time when called with a specific set of parameters.
22-
delete require.cache[require.resolve(BENCHMARK_FUNC_PATH)];
21+
// less time when called with a specific set of parameters. This used to use
22+
// `delete` instead of `Object.create(null)` but that resulted in many times
23+
// worse performance, so compare the runtime for this test if you change it
24+
// back or otherwise modify the `Object.create(null)` line below.
25+
// Ref: https://github.com/nodejs/node/pull/26237
26+
require.cache = Object.create(null);
2327
return result;
2428
}
2529

0 commit comments

Comments
 (0)