Skip to content

Commit

Permalink
tools,benchmark: increase lint compliance
Browse files Browse the repository at this point in the history
In the hopes of soon having the benchmark code linted, this change
groups all the likely non-controversial lint-compliance changes such as
indentation, semi-colon usage, and single-vs.-double quotation marks.

Other lint rules may have subtle performance implications in the V8
currently shipped with Node.js. Those changes will require more careful
review and will be in a separate change.

PR-URL: #5429
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
Trott authored and Fishrock123 committed Mar 2, 2016
1 parent c83725c commit b44b701
Show file tree
Hide file tree
Showing 49 changed files with 118 additions and 160 deletions.
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,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
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,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
16 changes: 8 additions & 8 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
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
16 changes: 7 additions & 9 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,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 @@ -49,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 @@ -87,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 @@ -121,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 @@ -141,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 @@ -210,7 +208,7 @@ function parseOpts(options) {
});
}
return num === 0 ? conf : null;
};
}

Benchmark.prototype.start = function() {
if (this._started)
Expand All @@ -228,8 +226,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
2 changes: 1 addition & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,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
1 change: 0 additions & 1 deletion benchmark/crypto/cipher-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ function legacyWrite(alice, bob, message, encoding, writes) {
written += dec.length;
dec = bob.final();
written += dec.length;
var bits = written * 8;
var gbits = written / (1024 * 1024 * 1024);
bench.end(gbits);
}
3 changes: 0 additions & 3 deletions benchmark/crypto/hash-stream-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ function main(conf) {
api = 'legacy';
}

var crypto = require('crypto');
var assert = require('assert');

var message;
var encoding;
switch (conf.type) {
Expand Down
3 changes: 0 additions & 3 deletions benchmark/crypto/hash-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ function main(conf) {
api = 'legacy';
}

var crypto = require('crypto');
var assert = require('assert');

var message;
var encoding;
switch (conf.type) {
Expand Down
3 changes: 1 addition & 2 deletions benchmark/crypto/rsa-encrypt-decrypt-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var bench = common.createBenchmark(main, {
});

function main(conf) {
var crypto = require('crypto');
var message = (new Buffer(conf.len)).fill('b');

bench.start();
Expand All @@ -39,7 +38,7 @@ function StreamWrite(algo, keylen, message, n, len) {
var publicKey = RSA_PublicPem[keylen];
for (var i = 0; i < n; i++) {
var enc = crypto.privateEncrypt(privateKey, message);
var clear = crypto.publicDecrypt(publicKey, enc);
crypto.publicDecrypt(publicKey, enc);
}

bench.end(kbits);
Expand Down
4 changes: 1 addition & 3 deletions benchmark/crypto/rsa-sign-verify-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var bench = common.createBenchmark(main, {
});

function main(conf) {
var crypto = require('crypto');
var message = (new Buffer(conf.len)).fill('b');

bench.start();
Expand All @@ -37,7 +36,6 @@ function StreamWrite(algo, keylen, message, writes, len) {
var kbits = bits / (1024);

var privateKey = RSA_PrivatePem[keylen];
var publicKey = RSA_PublicPem[keylen];
var s = crypto.createSign(algo);
var v = crypto.createVerify(algo);

Expand All @@ -46,7 +44,7 @@ function StreamWrite(algo, keylen, message, writes, len) {
v.update(message);
}

var sign = s.sign(privateKey, 'binary');
s.sign(privateKey, 'binary');
s.end();
v.end();

Expand Down
3 changes: 1 addition & 2 deletions benchmark/dgram/array-vs-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var num;
var type;
var chunk;
var chunks;
var encoding;

function main(conf) {
dur = +conf.dur;
Expand All @@ -30,7 +29,7 @@ function main(conf) {
type = conf.type;
chunks = +conf.chunks;

chunk = []
chunk = [];
for (var i = 0; i < chunks; i++) {
chunk.push(new Buffer(Math.round(len / chunks)));
}
Expand Down
3 changes: 1 addition & 2 deletions benchmark/dgram/multi-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var num;
var type;
var chunk;
var chunks;
var encoding;

function main(conf) {
dur = +conf.dur;
Expand All @@ -30,7 +29,7 @@ function main(conf) {
type = conf.type;
chunks = +conf.chunks;

chunk = []
chunk = [];
for (var i = 0; i < chunks; i++) {
chunk.push(new Buffer(Math.round(len / chunks)));
}
Expand Down
1 change: 0 additions & 1 deletion benchmark/dgram/offset-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var len;
var num;
var type;
var chunk;
var encoding;

function main(conf) {
dur = +conf.dur;
Expand Down
1 change: 0 additions & 1 deletion benchmark/dgram/single-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var len;
var num;
var type;
var chunk;
var encoding;

function main(conf) {
dur = +conf.dur;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/domain/domain-fn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var gargs = [1, 2, 3];

function main(conf) {

var args, ret, n = +conf.n;
var args, n = +conf.n;
var myArguments = gargs.slice(0, conf.arguments);
bench.start();

Expand Down Expand Up @@ -41,4 +41,4 @@ function fn(a, b, c) {
c = 3;

return a + b + c;
}
}
1 change: 0 additions & 1 deletion benchmark/events/ee-emit-multi-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function main(conf) {
var n = conf.n | 0;

var ee = new EventEmitter();
var listeners = [];

for (var k = 0; k < 10; k += 1)
ee.on('dummy', function() {});
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listener-count-on-prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function main(conf) {

bench.start();
for (var i = 0; i < n; i += 1) {
var r = ee.listenerCount('dummy');
ee.listenerCount('dummy');
}
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function main(conf) {

bench.start();
for (var i = 0; i < n; i += 1) {
var r = ee.listeners('dummy');
ee.listeners('dummy');
}
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function main(conf) {

bench.start();
for (var i = 0; i < n; i += 1) {
var r = ee.listeners('dummy');
ee.listeners('dummy');
}
bench.end(n);
}
5 changes: 2 additions & 3 deletions benchmark/fs-write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ function runTest(dur, size, type) {
break;
}

var writes = 0;
var fs = require('fs');
try { fs.unlinkSync('write_stream_throughput'); } catch (e) {}

var start
var start;
var end;
function done() {
var time = end[0] + end[1]/1E9;
var time = end[0] + end[1] / 1E9;
var written = fs.statSync('write_stream_throughput').size / 1024;
var rate = (written / time).toFixed(2);
console.log('fs_write_stream_dur_%d_size_%d_type_%s: %d',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/read-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var type, encoding, size;

var bench = common.createBenchmark(main, {
type: ['buf', 'asc', 'utf'],
size: [1024, 4096, 65535, 1024*1024]
size: [1024, 4096, 65535, 1024 * 1024]
});

function main(conf) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function main(conf) {
encoding = 'ascii';
break;
case 'utf':
chunk = new Array(Math.ceil(size/2) + 1).join('ü');
chunk = new Array(Math.ceil(size / 2) + 1).join('ü');
encoding = 'utf8';
break;
default:
Expand Down
7 changes: 3 additions & 4 deletions benchmark/http/_chunky_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var bench = common.createBenchmark(main, {
function main(conf) {
var len = +conf.len;
var num = +conf.num;
var type = conf.type;
var todo = [];
var headers = [];
// Chose 7 because 9 showed "Connection error" / "Connection closed"
Expand All @@ -24,7 +23,7 @@ function main(conf) {
headers.push(Array(i + 1).join('o'));

function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) {
todo = []
todo = [];
todo.push('GET / HTTP/1.1');
todo.push('Host: localhost');
todo.push('Connection: keep-alive');
Expand Down Expand Up @@ -63,7 +62,7 @@ function main(conf) {
var socket = net.connect(PIPE, function() {
bench.start();
WriteHTTPHeaders(socket, 1, len);
socket.setEncoding('utf8')
socket.setEncoding('utf8');
socket.on('data', function(d) {
var did = false;
var pattern = 'HTTP/1.1 200 OK\r\n';
Expand All @@ -73,7 +72,7 @@ function main(conf) {
success += 1;
did = true;
} else {
pattern = 'HTTP/1.1 '
pattern = 'HTTP/1.1 ';
if ((d.length === pattern.length && d === pattern) ||
(d.length > pattern.length &&
d.slice(0, pattern.length) === pattern)) {
Expand Down
1 change: 0 additions & 1 deletion benchmark/http/chunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'use strict';

var common = require('../common.js');
var PORT = common.PORT;

var bench = common.createBenchmark(main, {
num: [1, 4, 8, 16],
Expand Down
1 change: 0 additions & 1 deletion benchmark/http/end-vs-write-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'use strict';

var common = require('../common.js');
var PORT = common.PORT;

var bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'],
Expand Down
Loading

0 comments on commit b44b701

Please sign in to comment.