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

benchmark,tools: enable linting for benchmarks #5773

Closed
wants to merge 6 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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ bench-idle:
$(NODE) benchmark/idle_clients.js &

jslint:
$(NODE) tools/eslint/bin/eslint.js lib src test tools/doc tools/eslint-rules \
--rulesdir tools/eslint-rules
$(NODE) tools/eslint/bin/eslint.js benchmark lib src test tools/doc \
tools/eslint-rules --rulesdir tools/eslint-rules

CPPLINT_EXCLUDE ?=
CPPLINT_EXCLUDE += src/node_lttng.cc
Expand Down
5 changes: 4 additions & 1 deletion benchmark/arrays/var-int.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '),
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
n: [25]
});

Expand Down
5 changes: 4 additions & 1 deletion benchmark/arrays/zero-float.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '),
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
n: [25]
});

Expand Down
5 changes: 4 additions & 1 deletion benchmark/arrays/zero-int.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '),
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
n: [25]
});

Expand Down
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const assert = require('assert');
const common = require('../common.js');

Expand Down
8 changes: 5 additions & 3 deletions benchmark/buffers/buffer-base64-encode.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');

var bench = common.createBenchmark(main, {});
Expand All @@ -6,9 +7,10 @@ function main(conf) {
var N = 64 * 1024 * 1024;
var b = Buffer(N);
var s = '';
for (var i = 0; i < 256; ++i) s += String.fromCharCode(i);
for (var i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii');
var i;
for (i = 0; i < 256; ++i) s += String.fromCharCode(i);
for (i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii');
bench.start();
for (var i = 0; i < 32; ++i) b.toString('base64');
for (i = 0; i < 32; ++i) b.toString('base64');
bench.end(64);
}
3 changes: 2 additions & 1 deletion benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');

var bench = common.createBenchmark(main, {
Expand Down Expand Up @@ -43,7 +44,7 @@ function main(conf) {
var r = Buffer.byteLength(strings[index], encoding);

if (r !== results[index])
throw Error('incorrect return value');
throw new Error('incorrect return value');
}
bench.end(n);
}
Expand Down
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-compare.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');

var bench = common.createBenchmark(main, {
Expand Down
5 changes: 3 additions & 2 deletions benchmark/buffers/buffer-creation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SlowBuffer = require('buffer').SlowBuffer;
'use strict';
const SlowBuffer = require('buffer').SlowBuffer;

var common = require('../common.js');
var bench = common.createBenchmark(main, {
Expand All @@ -13,7 +14,7 @@ function main(conf) {
var clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
bench.start();
for (var i = 0; i < n * 1024; i++) {
b = new clazz(len);
new clazz(len);
}
bench.end(n);
}
6 changes: 5 additions & 1 deletion benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
var common = require('../common.js');
var fs = require('fs');
const path = require('path');

var bench = common.createBenchmark(main, {
search: ['@', 'SQ', '10x', '--l', 'Alice', 'Gryphon', 'Panther',
Expand All @@ -14,7 +16,9 @@ var bench = common.createBenchmark(main, {

function main(conf) {
var iter = (conf.iter) * 100000;
var aliceBuffer = fs.readFileSync(__dirname + '/../fixtures/alice.html');
var aliceBuffer = fs.readFileSync(
path.resolve(__dirname, '../fixtures/alice.html')
);
var search = conf.search;
var encoding = conf.encoding;

Expand Down
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-iterate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var SlowBuffer = require('buffer').SlowBuffer;
var common = require('../common.js');
var assert = require('assert');
Expand Down
9 changes: 5 additions & 4 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');

var bench = common.createBenchmark(main, {
Expand All @@ -21,10 +22,10 @@ function main(conf) {

buff.writeDoubleLE(0, 0, noAssert);
var testFunction = new Function('buff', [
"for (var i = 0; i !== " + len + "; i++) {",
" buff." + fn + "(0, " + JSON.stringify(noAssert) + ");",
"}"
].join("\n"));
'for (var i = 0; i !== ' + len + '; i++) {',
' buff.' + fn + '(0, ' + JSON.stringify(noAssert) + ');',
'}'
].join('\n'));
bench.start();
testFunction(buff);
bench.end(len / 1e6);
Expand Down
1 change: 1 addition & 0 deletions benchmark/buffers/buffer-slice.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');
var SlowBuffer = require('buffer').SlowBuffer;

Expand Down
5 changes: 3 additions & 2 deletions benchmark/buffers/buffer-tostring.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ function main(conf) {
const n = conf.n | 0;
const buf = Buffer(len).fill(42);

var i;
bench.start();
if (arg) {
for (var i = 0; i < n; i += 1)
for (i = 0; i < n; i += 1)
buf.toString('utf8');
} else {
for (var i = 0; i < n; i += 1)
for (i = 0; i < n; i += 1)
buf.toString();
}
bench.end(n);
Expand Down
18 changes: 9 additions & 9 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
noAssert: [false, true],
Expand Down Expand Up @@ -48,21 +48,21 @@ function main(conf) {
function benchInt(buff, fn, len, noAssert) {
var m = mod[fn];
var testFunction = new Function('buff', [
"for (var i = 0; i !== " + len + "; i++) {",
" buff." + fn + "(i & " + m + ", 0, " + JSON.stringify(noAssert) + ");",
"}"
].join("\n"));
'for (var i = 0; i !== ' + len + '; i++) {',
' buff.' + fn + '(i & ' + m + ', 0, ' + JSON.stringify(noAssert) + ');',
'}'
].join('\n'));
bench.start();
testFunction(buff);
bench.end(len / 1e6);
}

function benchFloat(buff, fn, len, noAssert) {
var testFunction = new Function('buff', [
"for (var i = 0; i !== " + len + "; i++) {",
" buff." + fn + "(i, 0, " + JSON.stringify(noAssert) + ");",
"}"
].join("\n"));
'for (var i = 0; i !== ' + len + '; i++) {',
' buff.' + fn + '(i, 0, ' + JSON.stringify(noAssert) + ');',
'}'
].join('\n'));
bench.start();
testFunction(buff);
bench.end(len / 1e6);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
type: ['Uint8', 'Uint16LE', 'Uint16BE',
Expand Down
19 changes: 9 additions & 10 deletions benchmark/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var fs = require('fs');
var path = require('path');
Expand Down Expand Up @@ -27,7 +28,7 @@ if (module === require.main) {
var tests = fs.readdirSync(dir);

if (testFilter) {
var filteredTests = tests.filter(function(item){
var filteredTests = tests.filter(function(item) {
if (item.lastIndexOf(testFilter) >= 0) {
return item;
}
Expand All @@ -48,7 +49,7 @@ function hasWrk() {
if (result.error && result.error.code === 'ENOENT') {
console.error('Couldn\'t locate `wrk` which is needed for running ' +
'benchmarks. Check benchmark/README.md for further instructions.');
process.exit(-1);
process.exit(-1);
}
}

Expand Down Expand Up @@ -86,7 +87,7 @@ function Benchmark(fn, options) {
this.options = options;
this.config = parseOpts(options);
this._name = require.main.filename.split(/benchmark[\/\\]/).pop();
this._start = [0,0];
this._start = [0, 0];
this._started = false;

var self = this;
Expand Down Expand Up @@ -120,7 +121,7 @@ Benchmark.prototype.http = function(p, args, cb) {

if (code) {
console.error('wrk failed with ' + code);
process.exit(code)
process.exit(code);
}
var match = out.match(regexp);
var qps = match && +match[1];
Expand All @@ -140,8 +141,6 @@ Benchmark.prototype._run = function() {
// some options weren't set.
// run with all combinations
var main = require.main.filename;
var settings = [];
var queueLen = 1;
var options = this.options;

var queue = Object.keys(options).reduce(function(set, key) {
Expand Down Expand Up @@ -192,7 +191,7 @@ function parseOpts(options) {
if (!match || !match[1] || !match[2] || !options[match[1]]) {
return null;
} else {
conf[match[1]] = isFinite(match[2]) ? +match[2] : match[2]
conf[match[1]] = isFinite(match[2]) ? +match[2] : match[2];
num--;
}
}
Expand All @@ -203,7 +202,7 @@ function parseOpts(options) {
});
}
return num === 0 ? conf : null;
};
}

Benchmark.prototype.start = function() {
if (this._started)
Expand All @@ -221,8 +220,8 @@ Benchmark.prototype.end = function(operations) {
if (typeof operations !== 'number')
throw new Error('called end() without specifying operation count');

var time = elapsed[0] + elapsed[1]/1e9;
var rate = operations/time;
var time = elapsed[0] + elapsed[1] / 1e9;
var rate = operations / time;
this.report(rate);
};

Expand Down
50 changes: 34 additions & 16 deletions benchmark/compare.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var usage = 'node benchmark/compare.js ' +
'<node-binary1> <node-binary2> ' +
'[--html] [--red|-r] [--green|-g] ' +
Expand Down Expand Up @@ -36,18 +37,19 @@ for (var i = 2; i < process.argv.length; i++) {
}
}

var start, green, red, reset, end;
if (!html) {
var start = '';
var green = '\033[1;32m';
var red = '\033[1;31m';
var reset = '\033[m';
var end = '';
start = '';
green = '\u001b[1;32m';
red = '\u001b[1;31m';
reset = '\u001b[m';
end = '';
} else {
var start = '<pre style="background-color:#333;color:#eee">';
var green = '<span style="background-color:#0f0;color:#000">';
var red = '<span style="background-color:#f00;color:#fff">';
var reset = '</span>';
var end = '</pre>';
start = '<pre style="background-color:#333;color:#eee">';
green = '<span style="background-color:#0f0;color:#000">';
red = '<span style="background-color:#f00;color:#fff">';
reset = '</span>';
end = '</pre>';
}

var runBench = process.env.NODE_BENCH || 'bench';
Expand Down Expand Up @@ -75,10 +77,15 @@ function run() {

var out = '';
var child;
if (Array.isArray(benchmarks) && benchmarks.length)
child = spawn(node, ['benchmark/common.js'].concat(benchmarks), { env: env });
else
if (Array.isArray(benchmarks) && benchmarks.length) {
child = spawn(
node,
['benchmark/common.js'].concat(benchmarks),
{ env: env }
);
} else {
child = spawn('make', [runBench], { env: env });
}
child.stdout.setEncoding('utf8');
child.stdout.on('data', function(c) {
out += c;
Expand Down Expand Up @@ -134,9 +141,20 @@ function compare() {
if (show === 'green' && !g || show === 'red' && !r)
return;

var r0 = util.format('%s%s: %d%s', g, nodes[0], n0.toPrecision(5), g ? reset : '');
var r1 = util.format('%s%s: %d%s', r, nodes[1], n1.toPrecision(5), r ? reset : '');
var pct = c + pct + '%' + reset;
var r0 = util.format(
'%s%s: %d%s',
g,
nodes[0],
n0.toPrecision(5), g ? reset : ''
);
var r1 = util.format(
'%s%s: %d%s',
r,
nodes[1],
n1.toPrecision(5), r ? reset : ''
);
pct = c + pct + '%' + reset;

var l = util.format('%s: %s %s', bench, r0, r1);
maxLen = Math.max(l.length + pct.length, maxLen);
return [l, pct];
Expand Down
3 changes: 2 additions & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');
var crypto = require('crypto');
var keylen = {'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32};
Expand Down Expand Up @@ -30,7 +31,7 @@ function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) {
var bob = crypto.createDecipheriv(cipher, key, iv);
bob.setAuthTag(tag);
bob.setAAD(associate_data);
var clear = bob.update(enc);
bob.update(enc);
bob.final();
}

Expand Down
Loading