Skip to content

Commit

Permalink
benchmark: remove noAssert argument
Browse files Browse the repository at this point in the history
This removes the `noAssert` argument and also adds some more tests.

PR-URL: #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>
  • Loading branch information
BridgeAR committed Mar 2, 2018
1 parent e8bb1f3 commit 81aaab7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
8 changes: 3 additions & 5 deletions benchmark/buffers/buffer-read-float.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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);
}
13 changes: 5 additions & 8 deletions benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 3 additions & 5 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
54 changes: 40 additions & 14 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ const types = [
'UInt16BE',
'UInt32LE',
'UInt32BE',
'UIntLE',
'UIntBE',
'Int8',
'Int16LE',
'Int16BE',
'Int32LE',
'Int32BE',
'IntLE',
'IntBE',
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE'
];

const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
millions: [1]
Expand All @@ -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,
Expand All @@ -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) {
const m = mod[fn];
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](i & m, 0);
}
bench.end(millions);
}

function benchInt(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 & m, 0, noAssert);
buff[fn](i & m, 0, byte);
}
bench.end(millions);
}

function benchFloat(buff, fn, millions, noAssert) {
function benchFloat(buff, fn, millions) {
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
buff[fn](i, 0, noAssert);
buff[fn](i, 0);
}
bench.end(millions);
}
1 change: 0 additions & 1 deletion test/sequential/test-benchmark-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ runBenchmark('buffers',
'millions=0.000001',
'method=',
'n=1',
'noAssert=true',
'pieces=1',
'pieceSize=1',
'search=@',
Expand Down

0 comments on commit 81aaab7

Please sign in to comment.