diff --git a/benchmark/buffers/buffer-read-float.js b/benchmark/buffers/buffer-read-float.js index afd9edf5578308..e105642972d857 100644 --- a/benchmark/buffers/buffer-read-float.js +++ b/benchmark/buffers/buffer-read-float.js @@ -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); } diff --git a/benchmark/buffers/buffer-read-with-byteLength.js b/benchmark/buffers/buffer-read-with-byteLength.js index 9fe5e6f4bf43ff..1858c4fd965e26 100644 --- a/benchmark/buffers/buffer-read-with-byteLength.js +++ b/benchmark/buffers/buffer-read-with-byteLength.js @@ -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); } diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 868f5cede8bd2d..88a46cb29079f6 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -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); } diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index 823e95bf15d704..42ea9aa093cb88 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -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) { + 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); } diff --git a/test/sequential/test-benchmark-buffer.js b/test/sequential/test-benchmark-buffer.js index f5e0c692f367be..4eb4415a61dd7f 100644 --- a/test/sequential/test-benchmark-buffer.js +++ b/test/sequential/test-benchmark-buffer.js @@ -16,7 +16,6 @@ runBenchmark('buffers', 'millions=0.000001', 'method=', 'n=1', - 'noAssert=true', 'pieces=1', 'pieceSize=1', 'search=@',