diff --git a/benchmark/buffers/buffer-read-with-byteLength.js b/benchmark/buffers/buffer-read-with-byteLength.js new file mode 100644 index 00000000000000..013947da9dd485 --- /dev/null +++ b/benchmark/buffers/buffer-read-with-byteLength.js @@ -0,0 +1,34 @@ +'use strict'; +const common = require('../common.js'); + +const types = [ + 'IntLE', + 'IntBE', +]; + +const bench = common.createBenchmark(main, { + noAssert: ['false', 'true'], + buffer: ['fast', 'slow'], + type: types, + millions: [1], + byteLength: [1, 2, 4, 6] +}); + +function main(conf) { + const noAssert = conf.noAssert === 'true'; + const len = conf.millions * 1e6; + const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; + const buff = new clazz(8); + const type = conf.type || 'UInt8'; + const fn = `read${type}`; + + buff.writeDoubleLE(0, 0, noAssert); + const testFunction = new Function('buff', ` + for (var i = 0; i !== ${len}; i++) { + buff.${fn}(0, ${conf.byteLength}, ${JSON.stringify(noAssert)}); + } + `); + bench.start(); + testFunction(buff); + bench.end(len / 1e6); +} diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 22f8dcbd3dea12..339da75befce4d 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -15,9 +15,7 @@ const types = [ 'FloatLE', 'FloatBE', 'DoubleLE', - 'DoubleBE', - 'IntLE', - 'IntBE', + 'DoubleBE' ]; const bench = common.createBenchmark(main, { @@ -36,19 +34,11 @@ function main(conf) { const fn = `read${type}`; buff.writeDoubleLE(0, 0, noAssert); - - var call; - if (fn === 'readIntLE' || fn === 'readIntBE') { - call = `buff.${fn}(0, 1, ${JSON.stringify(noAssert)})`; - } else { - call = `buff.${fn}(0, ${JSON.stringify(noAssert)})`; - } - - const testFunction = new Function( - 'buff', - `for (var i = 0; i !== ${len}; ++i) { ${call}; }` - ); - + const testFunction = new Function('buff', ` + for (var i = 0; i !== ${len}; i++) { + buff.${fn}(0, ${JSON.stringify(noAssert)}); + } + `); bench.start(); testFunction(buff); bench.end(len / 1e6); diff --git a/test/sequential/test-benchmark-buffer.js b/test/sequential/test-benchmark-buffer.js index 26600cf4f26a87..2cee628ada8d79 100644 --- a/test/sequential/test-benchmark-buffer.js +++ b/test/sequential/test-benchmark-buffer.js @@ -9,7 +9,9 @@ runBenchmark('buffers', 'aligned=true', 'args=1', 'buffer=fast', + 'byteLength=1', 'encoding=utf8', + 'endian=BE', 'len=2', 'method=', 'n=1', @@ -20,6 +22,7 @@ runBenchmark('buffers', 'size=1', 'source=array', 'type=', + 'value=0', 'withTotalLength=0' ], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });