@@ -6,21 +6,24 @@ if (!common.hasCrypto)
66if ( ! common . enoughTestMem )
77 common . skip ( 'memory-intensive test' ) ;
88
9- const fixtures = require ( '../common/fixtures' ) ;
109const assert = require ( 'assert' ) ;
1110const 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
2629function getTValue ( compareFunc ) {
0 commit comments