Skip to content

Commit

Permalink
benchmark: improve buffer.readInt(B|L)E benchmarks
Browse files Browse the repository at this point in the history
Split them into their own benhmark file and use different byteLength
values.

PR-URL: nodejs#11146
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
Trott authored and BridgeAR committed Jan 5, 2018
1 parent d964ffe commit 94d6487
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
34 changes: 34 additions & 0 deletions benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
@@ -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);
}
22 changes: 6 additions & 16 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const types = [
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE',
'IntLE',
'IntBE',
'DoubleBE'
];

const bench = common.createBenchmark(main, {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/sequential/test-benchmark-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ runBenchmark('buffers',
'aligned=true',
'args=1',
'buffer=fast',
'byteLength=1',
'encoding=utf8',
'endian=BE',
'len=2',
'method=',
'n=1',
Expand All @@ -20,6 +22,7 @@ runBenchmark('buffers',
'size=1',
'source=array',
'type=',
'value=0',
'withTotalLength=0'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 comments on commit 94d6487

Please sign in to comment.