summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-02-21 03:26:27 -0800
committerRich Trott <rtrott@gmail.com>2019-02-21 20:22:48 -0800
commiteb9e6c015705847190147201c587e1e668358a78 (patch)
tree61ff67d4a38ebc764590226ac1cb41bb67feb9ef /test
parentd1011f6bbfadfa254925014896aa710f02403770 (diff)
downloadandroid-node-v8-eb9e6c015705847190147201c587e1e668358a78.tar.gz
android-node-v8-eb9e6c015705847190147201c587e1e668358a78.tar.bz2
android-node-v8-eb9e6c015705847190147201c587e1e668358a78.zip
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: https://github.com/nodejs/node/issues/25984 Refs: https://github.com/nodejs/node/issues/26229 PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/crypto-timing-safe-equal-benchmark-func.js17
-rw-r--r--test/pummel/test-crypto-timing-safe-equal-benchmarks.js27
2 files changed, 15 insertions, 29 deletions
diff --git a/test/fixtures/crypto-timing-safe-equal-benchmark-func.js b/test/fixtures/crypto-timing-safe-equal-benchmark-func.js
deleted file mode 100644
index 96470e3e44..0000000000
--- a/test/fixtures/crypto-timing-safe-equal-benchmark-func.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict';
-
-const assert = require('assert');
-module.exports = (compareFunc, firstBufFill, secondBufFill, bufSize) => {
- const firstBuffer = Buffer.alloc(bufSize, firstBufFill);
- const secondBuffer = Buffer.alloc(bufSize, secondBufFill);
-
- const startTime = process.hrtime();
- const result = compareFunc(firstBuffer, secondBuffer);
- const endTime = process.hrtime(startTime);
-
- // Ensure that the result of the function call gets used, so it doesn't
- // get discarded due to engine optimizations.
- assert.strictEqual(result, firstBufFill === secondBufFill);
-
- return endTime[0] * 1e9 + endTime[1];
-};
diff --git a/test/pummel/test-crypto-timing-safe-equal-benchmarks.js b/test/pummel/test-crypto-timing-safe-equal-benchmarks.js
index 0592b9a0d6..b649b071e1 100644
--- a/test/pummel/test-crypto-timing-safe-equal-benchmarks.js
+++ b/test/pummel/test-crypto-timing-safe-equal-benchmarks.js
@@ -6,21 +6,24 @@ if (!common.hasCrypto)
if (!common.enoughTestMem)
common.skip('memory-intensive test');
-const fixtures = require('../common/fixtures');
const assert = require('assert');
const crypto = require('crypto');
-const BENCHMARK_FUNC_PATH =
- `${fixtures.fixturesDir}/crypto-timing-safe-equal-benchmark-func`;
-function runOneBenchmark(...args) {
- const benchmarkFunc = require(BENCHMARK_FUNC_PATH);
- const result = benchmarkFunc(...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)];
- return result;
+function runOneBenchmark(compareFunc, firstBufFill, secondBufFill, bufSize) {
+ return eval(`
+ const firstBuffer = Buffer.alloc(bufSize, firstBufFill);
+ const secondBuffer = Buffer.alloc(bufSize, secondBufFill);
+
+ const startTime = process.hrtime();
+ const result = compareFunc(firstBuffer, secondBuffer);
+ const endTime = process.hrtime(startTime);
+
+ // Ensure that the result of the function call gets used, so it doesn't
+ // get discarded due to engine optimizations.
+ assert.strictEqual(result, firstBufFill === secondBufFill);
+
+ endTime[0] * 1e9 + endTime[1];
+ `);
}
function getTValue(compareFunc) {