Skip to content

Commit 4f4efb9

Browse files
TrottMylesBorins
authored andcommitted
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: #15175 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]
1 parent c916c1c commit 4f4efb9

6 files changed

+26
-21
lines changed

benchmark/buffers/buffer-creation.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function main(conf) {
1919
const len = +conf.len;
2020
const n = +conf.n;
2121
switch (conf.type) {
22+
case '':
2223
case 'fast-alloc':
2324
bench.start();
2425
for (let i = 0; i < n * 1024; i++) {

benchmark/buffers/buffer-iterate.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ var methods = {
1717
};
1818

1919
function main(conf) {
20-
var len = +conf.size;
21-
var clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
22-
var buffer = new clazz(len);
20+
const len = +conf.size;
21+
const clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
22+
const buffer = new clazz(len);
2323
buffer.fill(0);
2424

25-
methods[conf.method](buffer, conf.n);
25+
const method = conf.method || 'for';
26+
methods[method](buffer, conf.n);
2627
}
2728

2829

benchmark/buffers/buffer-read.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ var bench = common.createBenchmark(main, {
2626
});
2727

2828
function main(conf) {
29-
var noAssert = conf.noAssert === 'true';
30-
var len = +conf.millions * 1e6;
31-
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
32-
var buff = new clazz(8);
33-
var fn = `read${conf.type}`;
29+
const noAssert = conf.noAssert === 'true';
30+
const len = +conf.millions * 1e6;
31+
const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
32+
const buff = new clazz(8);
33+
const type = conf.type || 'UInt8';
34+
const fn = `read${type}`;
3435

3536
buff.writeDoubleLE(0, 0, noAssert);
36-
var testFunction = new Function('buff', `
37+
const testFunction = new Function('buff', `
3738
for (var i = 0; i !== ${len}; i++) {
3839
buff.${fn}(0, ${JSON.stringify(noAssert)});
3940
}

benchmark/buffers/buffer-swap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function genMethod(method) {
7373
}
7474

7575
function main(conf) {
76-
const method = conf.method;
76+
const method = conf.method || 'swap16';
7777
const len = conf.len | 0;
7878
const n = conf.n | 0;
7979
const aligned = conf.aligned || 'true';

benchmark/buffers/buffer-write.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ var mod = {
4646
};
4747

4848
function main(conf) {
49-
var noAssert = conf.noAssert === 'true';
50-
var len = +conf.millions * 1e6;
51-
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
52-
var buff = new clazz(8);
53-
var fn = `write${conf.type}`;
49+
const noAssert = conf.noAssert === 'true';
50+
const len = +conf.millions * 1e6;
51+
const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
52+
const buff = new clazz(8);
53+
const type = conf.type || 'UInt8';
54+
const fn = `write${type}`;
5455

5556
if (/Int/.test(fn))
5657
benchInt(buff, fn, len, noAssert);

benchmark/buffers/dataview-set.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ var mod = {
4040
};
4141

4242
function main(conf) {
43-
var len = +conf.millions * 1e6;
44-
var ab = new ArrayBuffer(8);
45-
var dv = new DataView(ab, 0, 8);
46-
var le = /LE$/.test(conf.type);
47-
var fn = `set${conf.type.replace(/[LB]E$/, '')}`;
43+
const len = +conf.millions * 1e6;
44+
const ab = new ArrayBuffer(8);
45+
const dv = new DataView(ab, 0, 8);
46+
const type = conf.type || 'Uint8';
47+
const le = /LE$/.test(type);
48+
const fn = `set${type.replace(/[LB]E$/, '')}`;
4849

4950
if (/int/i.test(fn))
5051
benchInt(dv, fn, len, le);

0 commit comments

Comments
 (0)