benchmark: improve buffer.readInt(B|L)E benchmarks

Split them into their own benhmark file and use different byteLength
values.

PR-URL: https://github.com/nodejs/node/pull/11146
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Rich Trott 2018-01-01 20:00:59 -08:00 committed by Ruben Bridgewater
parent d964ffeec3
commit 94d64877ff
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 43 additions and 16 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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 });