Skip to content

Commit

Permalink
test: improve performance of test-crypto-timing-safe-equal-benchmarks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Trott committed Feb 21, 2019
1 parent d1011f6 commit 3b626d2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/pummel/test-crypto-timing-safe-equal-benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ function runOneBenchmark(...args) {

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

Expand Down

0 comments on commit 3b626d2

Please sign in to comment.