0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

benchmark: remove noAssert argument

This removes the `noAssert` argument and also adds some more tests.

PR-URL: https://github.com/nodejs/node/pull/18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Ruben Bridgewater 2018-01-30 21:06:59 +01:00
parent e8bb1f35df
commit 81aaab75ca
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
5 changed files with 51 additions and 33 deletions

View File

@ -2,15 +2,13 @@
const common = require('../common.js');
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
type: ['Double', 'Float'],
endian: ['BE', 'LE'],
value: ['zero', 'big', 'small', 'inf', 'nan'],
millions: [1]
});
function main({ noAssert, millions, type, endian, value }) {
noAssert = noAssert === 'true';
function main({ millions, type, endian, value }) {
type = type || 'Double';
const buff = Buffer.alloc(8);
const fn = `read${type}${endian}`;
@ -31,11 +29,11 @@ function main({ noAssert, millions, type, endian, value }) {
},
};
buff[`write${type}${endian}`](values[type][value], 0, noAssert);
buff[`write${type}${endian}`](values[type][value], 0);
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](0, noAssert);
buff[fn](0);
}
bench.end(millions);
}

View File

@ -9,24 +9,21 @@ const types = [
];
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
millions: [1],
byteLength: [1, 2, 4, 6]
byteLength: [1, 2, 3, 4, 5, 6]
});
function main({ millions, noAssert, buf, type, byteLength }) {
noAssert = noAssert === 'true';
type = type || 'UInt8';
function main({ millions, buf, type, byteLength }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `read${type}`;
const fn = `read${type || 'IntBE'}`;
buff.writeDoubleLE(0, 0, noAssert);
buff.writeDoubleLE(0, 0);
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](0, byteLength, noAssert);
buff[fn](0, byteLength);
}
bench.end(millions);
}

View File

@ -19,22 +19,20 @@ const types = [
];
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
millions: [1]
});
function main({ noAssert, millions, buf, type }) {
noAssert = noAssert === 'true';
function main({ millions, buf, type }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `read${type || 'UInt8'}`;
buff.writeDoubleLE(0, 0, noAssert);
buff.writeDoubleLE(0, 0);
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](0, noAssert);
buff[fn](0);
}
bench.end(millions);
}

View File

@ -7,11 +7,15 @@ const types = [
'UInt16BE',
'UInt32LE',
'UInt32BE',
'UIntLE',
'UIntBE',
'Int8',
'Int16LE',
'Int16BE',
'Int32LE',
'Int32BE',
'IntLE',
'IntBE',
'FloatLE',
'FloatBE',
'DoubleLE',
@ -19,7 +23,6 @@ const types = [
];
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
millions: [1]
@ -28,9 +31,9 @@ const bench = common.createBenchmark(main, {
const INT8 = 0x7f;
const INT16 = 0x7fff;
const INT32 = 0x7fffffff;
const UINT8 = (INT8 * 2) + 1;
const UINT16 = (INT16 * 2) + 1;
const UINT32 = INT32;
const INT48 = 0x7fffffffffff;
const UINT8 = 0xff;
const UINT16 = 0xffff;
const mod = {
writeInt8: INT8,
@ -41,34 +44,57 @@ const mod = {
writeUInt8: UINT8,
writeUInt16BE: UINT16,
writeUInt16LE: UINT16,
writeUInt32BE: UINT32,
writeUInt32LE: UINT32
writeUInt32BE: INT32,
writeUInt32LE: INT32,
writeUIntLE: INT8,
writeUIntBE: INT16,
writeIntLE: INT32,
writeIntBE: INT48
};
function main({ noAssert, millions, buf, type }) {
const byteLength = {
writeUIntLE: 1,
writeUIntBE: 2,
writeIntLE: 4,
writeIntBE: 6
};
function main({ millions, buf, type }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `write${type || 'UInt8'}`;
if (/Int/.test(fn))
benchInt(buff, fn, millions, noAssert);
if (!/\d/.test(fn))
benchSpecialInt(buff, fn, millions);
else if (/Int/.test(fn))
benchInt(buff, fn, millions);
else
benchFloat(buff, fn, millions, noAssert);
benchFloat(buff, fn, millions);
}
function benchInt(buff, fn, millions, noAssert) {
function benchInt(buff, fn, millions) {
const m = mod[fn];
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](i & m, 0, noAssert);
buff[fn](i & m, 0);
}
bench.end(millions);
}
function benchFloat(buff, fn, millions, noAssert) {
function benchSpecialInt(buff, fn, millions) {
const m = mod[fn];
const byte = byteLength[fn];
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](i, 0, noAssert);
buff[fn](i & m, 0, byte);
}
bench.end(millions);
}
function benchFloat(buff, fn, millions) {
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](i, 0);
}
bench.end(millions);
}

View File

@ -16,7 +16,6 @@ runBenchmark('buffers',
'millions=0.000001',
'method=',
'n=1',
'noAssert=true',
'pieces=1',
'pieceSize=1',
'search=@',