mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
c678ecbca0
The `crypto.timingSafeEqual` test still seems to be a bit flaky. This makes a few changes to the test: * Separates the basic usage and the benchmarking into different tests * Moves the timing-sensitive benchmark function into a separate module, and reparses the module on every iteration of the loop to avoid shared state between timing measurements. PR-URL: https://github.com/nodejs/node/pull/8456 Reviewed-By: James M Snell <jasnell@gmail.com>
18 lines
613 B
JavaScript
18 lines
613 B
JavaScript
'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];
|
|
};
|