Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca18525

Browse filesBrowse files
Trottrvagg
authored andcommitted
test: improve performance of test-crypto-timing-safe-equal-benchmarks
Using `eval()` rather than `require()`'ing a fixture and deleting it from the cache results in a roughtly 10x improvement in running time. Fixes: #25984 Refs: #26229 PR-URL: #26237 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 7e26ca6 commit ca18525
Copy full SHA for ca18525

File tree

Expand file treeCollapse file tree

2 files changed

+15
-29
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-29
lines changed
Open diff view settings
Collapse file

‎test/fixtures/crypto-timing-safe-equal-benchmark-func.js‎

Copy file name to clipboardExpand all lines: test/fixtures/crypto-timing-safe-equal-benchmark-func.js
-17Lines changed: 0 additions & 17 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboardExpand all lines: test/pummel/test-crypto-timing-safe-equal-benchmarks.js
+15-12Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ if (!common.hasCrypto)
66
if (!common.enoughTestMem)
77
common.skip('memory-intensive test');
88

9-
const fixtures = require('../common/fixtures');
109
const assert = require('assert');
1110
const crypto = require('crypto');
1211

13-
const BENCHMARK_FUNC_PATH =
14-
`${fixtures.fixturesDir}/crypto-timing-safe-equal-benchmark-func`;
15-
function runOneBenchmark(...args) {
16-
const benchmarkFunc = require(BENCHMARK_FUNC_PATH);
17-
const result = benchmarkFunc(...args);
18-
19-
// Don't let the comparison function get cached. This avoid a timing
20-
// 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)];
23-
return result;
12+
function runOneBenchmark(compareFunc, firstBufFill, secondBufFill, bufSize) {
13+
return eval(`
14+
const firstBuffer = Buffer.alloc(bufSize, firstBufFill);
15+
const secondBuffer = Buffer.alloc(bufSize, secondBufFill);
16+
17+
const startTime = process.hrtime();
18+
const result = compareFunc(firstBuffer, secondBuffer);
19+
const endTime = process.hrtime(startTime);
20+
21+
// Ensure that the result of the function call gets used, so it doesn't
22+
// get discarded due to engine optimizations.
23+
assert.strictEqual(result, firstBufFill === secondBufFill);
24+
25+
endTime[0] * 1e9 + endTime[1];
26+
`);
2427
}
2528

2629
function getTValue(compareFunc) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.