mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 15:30:56 +01:00
5e4545e18f
* Move numbers into configuration * Add buffer comparison benchmark * Add assert.deepStrictEqual benchmarks PR-URL: https://github.com/nodejs/node/pull/11092 Reviewed-By: James M Snell <jasnell@gmail.com>
41 lines
908 B
JavaScript
41 lines
908 B
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e3],
|
|
len: [1e2],
|
|
method: ['strict', 'nonstrict']
|
|
});
|
|
|
|
function main(conf) {
|
|
const n = +conf.n;
|
|
const len = +conf.len;
|
|
var i;
|
|
|
|
const data = Buffer.allocUnsafe(len);
|
|
const actual = Buffer.alloc(len);
|
|
const expected = Buffer.alloc(len);
|
|
data.copy(actual);
|
|
data.copy(expected);
|
|
|
|
switch (conf.method) {
|
|
case 'strict':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
// eslint-disable-next-line no-restricted-properties
|
|
assert.deepEqual(actual, expected);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'nonstrict':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
assert.deepStrictEqual(actual, expected);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
throw new Error('Unsupported method');
|
|
}
|
|
}
|