benchmark: add default configs to buffer benchmark
Add default values to use for `type` and `method` in `buffer` benchmarks when the provided configuration value is an empty string. This is primarily useful for testing, so the test can request a single iteration without having to worry about providing different valid values for the different benchmarks. While making this change, some `var` instances in immediately surrounding code were changed to `const`. In some cases, `var` had been preserved so that the benchmarks would continue to run in versions of Node.js prior to 4.0.0. However, now that `const` has been introduced into the benchmark `common` module, the benchmarks will no longer run with those versions of Node.js anyway. PR-URL: https://github.com/nodejs/node/pull/15175 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com
This commit is contained in:
parent
81b2a89ad3
commit
b62343d83c
@ -19,6 +19,7 @@ function main(conf) {
|
|||||||
const len = +conf.len;
|
const len = +conf.len;
|
||||||
const n = +conf.n;
|
const n = +conf.n;
|
||||||
switch (conf.type) {
|
switch (conf.type) {
|
||||||
|
case '':
|
||||||
case 'fast-alloc':
|
case 'fast-alloc':
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n * 1024; i++) {
|
for (let i = 0; i < n * 1024; i++) {
|
||||||
|
@ -17,12 +17,13 @@ var methods = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
var len = +conf.size;
|
const len = +conf.size;
|
||||||
var clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
|
const clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
|
||||||
var buffer = new clazz(len);
|
const buffer = new clazz(len);
|
||||||
buffer.fill(0);
|
buffer.fill(0);
|
||||||
|
|
||||||
methods[conf.method](buffer, conf.n);
|
const method = conf.method || 'for';
|
||||||
|
methods[method](buffer, conf.n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,14 +26,15 @@ var bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
var noAssert = conf.noAssert === 'true';
|
const noAssert = conf.noAssert === 'true';
|
||||||
var len = +conf.millions * 1e6;
|
const len = +conf.millions * 1e6;
|
||||||
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
||||||
var buff = new clazz(8);
|
const buff = new clazz(8);
|
||||||
var fn = `read${conf.type}`;
|
const type = conf.type || 'UInt8';
|
||||||
|
const fn = `read${type}`;
|
||||||
|
|
||||||
buff.writeDoubleLE(0, 0, noAssert);
|
buff.writeDoubleLE(0, 0, noAssert);
|
||||||
var testFunction = new Function('buff', `
|
const testFunction = new Function('buff', `
|
||||||
for (var i = 0; i !== ${len}; i++) {
|
for (var i = 0; i !== ${len}; i++) {
|
||||||
buff.${fn}(0, ${JSON.stringify(noAssert)});
|
buff.${fn}(0, ${JSON.stringify(noAssert)});
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ function genMethod(method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const method = conf.method;
|
const method = conf.method || 'swap16';
|
||||||
const len = conf.len | 0;
|
const len = conf.len | 0;
|
||||||
const n = conf.n | 0;
|
const n = conf.n | 0;
|
||||||
const aligned = conf.aligned || 'true';
|
const aligned = conf.aligned || 'true';
|
||||||
|
@ -46,11 +46,12 @@ var mod = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
var noAssert = conf.noAssert === 'true';
|
const noAssert = conf.noAssert === 'true';
|
||||||
var len = +conf.millions * 1e6;
|
const len = +conf.millions * 1e6;
|
||||||
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
||||||
var buff = new clazz(8);
|
const buff = new clazz(8);
|
||||||
var fn = `write${conf.type}`;
|
const type = conf.type || 'UInt8';
|
||||||
|
const fn = `write${type}`;
|
||||||
|
|
||||||
if (/Int/.test(fn))
|
if (/Int/.test(fn))
|
||||||
benchInt(buff, fn, len, noAssert);
|
benchInt(buff, fn, len, noAssert);
|
||||||
|
@ -40,11 +40,12 @@ var mod = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
var len = +conf.millions * 1e6;
|
const len = +conf.millions * 1e6;
|
||||||
var ab = new ArrayBuffer(8);
|
const ab = new ArrayBuffer(8);
|
||||||
var dv = new DataView(ab, 0, 8);
|
const dv = new DataView(ab, 0, 8);
|
||||||
var le = /LE$/.test(conf.type);
|
const type = conf.type || 'Uint8';
|
||||||
var fn = `set${conf.type.replace(/[LB]E$/, '')}`;
|
const le = /LE$/.test(type);
|
||||||
|
const fn = `set${type.replace(/[LB]E$/, '')}`;
|
||||||
|
|
||||||
if (/int/i.test(fn))
|
if (/int/i.test(fn))
|
||||||
benchInt(dv, fn, len, le);
|
benchInt(dv, fn, len, le);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user