Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test-benchmark-buffer #15175

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function main(conf) {
const len = +conf.len;
const n = +conf.n;
switch (conf.type) {
case '':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a short description why this is necessary.
E.g. // Used for testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oy... I just landed this then saw this comment, my apologies for missing it

case 'fast-alloc':
bench.start();
for (let i = 0; i < n * 1024; i++) {
Expand Down
9 changes: 5 additions & 4 deletions benchmark/buffers/buffer-iterate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ var methods = {
};

function main(conf) {
var len = +conf.size;
var clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
var buffer = new clazz(len);
const len = +conf.size;
const clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
const buffer = new clazz(len);
buffer.fill(0);

methods[conf.method](buffer, conf.n);
const method = conf.method || 'for';
methods[method](buffer, conf.n);
}


Expand Down
13 changes: 7 additions & 6 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ var bench = common.createBenchmark(main, {
});

function main(conf) {
var noAssert = conf.noAssert === 'true';
var len = +conf.millions * 1e6;
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
var buff = new clazz(8);
var fn = `read${conf.type}`;
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);
var testFunction = new Function('buff', `
const testFunction = new Function('buff', `
for (var i = 0; i !== ${len}; i++) {
buff.${fn}(0, ${JSON.stringify(noAssert)});
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function genMethod(method) {
}

function main(conf) {
const method = conf.method;
const method = conf.method || 'swap16';
const len = conf.len | 0;
const n = conf.n | 0;
const aligned = conf.aligned || 'true';
Expand Down
11 changes: 6 additions & 5 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ var mod = {
};

function main(conf) {
var noAssert = conf.noAssert === 'true';
var len = +conf.millions * 1e6;
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
var buff = new clazz(8);
var fn = `write${conf.type}`;
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 = `write${type}`;

if (/Int/.test(fn))
benchInt(buff, fn, len, noAssert);
Expand Down
11 changes: 6 additions & 5 deletions benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ var mod = {
};

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

if (/int/i.test(fn))
benchInt(dv, fn, len, le);
Expand Down
34 changes: 34 additions & 0 deletions test/parallel/test-benchmark-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

require('../common');

// Minimal test for buffer benchmarks. This makes sure the benchmarks aren't
// completely broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'aligned=true',
'--set', 'args=1',
'--set', 'buffer=fast',
'--set', 'encoding=utf8',
'--set', 'len=2',
'--set', 'method=',
'--set', 'n=1',
'--set', 'noAssert=true',
'--set', 'pieces=1',
'--set', 'pieceSize=1',
'--set', 'search=@',
'--set', 'size=1',
'--set', 'source=array',
'--set', 'type=',
'--set', 'withTotalLength=0',
'buffers'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});