@@ -6,21 +6,24 @@ if (!common.hasCrypto)
6
6
if ( ! common . enoughTestMem )
7
7
common . skip ( 'memory-intensive test' ) ;
8
8
9
- const fixtures = require ( '../common/fixtures' ) ;
10
9
const assert = require ( 'assert' ) ;
11
10
const crypto = require ( 'crypto' ) ;
12
11
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
+ ` ) ;
24
27
}
25
28
26
29
function getTValue ( compareFunc ) {
0 commit comments