Skip to content

Commit

Permalink
benchmark: reformat code for clarity
Browse files Browse the repository at this point in the history
Some of the benchmark code can be a little dense. Not *very* hard to
read but perhaps harder than it needs to be.

These changes (many of them whitespace-only) hopefully improve
readability.

There are also a few cases of `assert.equal()` that are changed to
`assert.strictEqual()`.

PR-URL: #9790
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Dec 20, 2016
1 parent e94b72e commit c32c86b
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 73 deletions.
18 changes: 15 additions & 3 deletions benchmark/arrays/var-int.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
'use strict';
var common = require('../common.js');

var types = [
'Array',
'Buffer',
'Int8Array',
'Uint8Array',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array'
];

var bench = common.createBenchmark(main, {
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
type: types,
n: [25]
});

Expand Down
18 changes: 15 additions & 3 deletions benchmark/arrays/zero-float.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
'use strict';
var common = require('../common.js');

var types = [
'Array',
'Buffer',
'Int8Array',
'Uint8Array',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array'
];

var bench = common.createBenchmark(main, {
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
type: types,
n: [25]
});

Expand Down
18 changes: 15 additions & 3 deletions benchmark/arrays/zero-int.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
'use strict';
var common = require('../common.js');

var types = [
'Array',
'Buffer',
'Int8Array',
'Uint8Array',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array'
];

var bench = common.createBenchmark(main, {
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
'Float64Array'],
type: types,
n: [25]
});

Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const bench = common.createBenchmark(main, {});
function main(conf) {
const s = 'abcd'.repeat(8 << 20);
s.match(/./); // Flatten string.
assert.equal(s.length % 4, 0);
assert.strictEqual(s.length % 4, 0);
const b = Buffer.allocUnsafe(s.length / 4 * 3);
b.write(s, 0, s.length, 'base64');
bench.start();
Expand Down
24 changes: 19 additions & 5 deletions benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ var common = require('../common.js');
var fs = require('fs');
const path = require('path');

const searchStrings = [
'@',
'SQ',
'10x',
'--l',
'Alice',
'Gryphon',
'Panther',
'Ou est ma chatte?',
'found it very',
'among mad people',
'neighbouring pool',
'Soo--oop',
'aaaaaaaaaaaaaaaaa',
'venture to go near the house till she had brought herself down to',
'</i> to the Caterpillar'
];

var bench = common.createBenchmark(main, {
search: ['@', 'SQ', '10x', '--l', 'Alice', 'Gryphon', 'Panther',
'Ou est ma chatte?', 'found it very', 'among mad people',
'neighbouring pool', 'Soo--oop', 'aaaaaaaaaaaaaaaaa',
'venture to go near the house till she had brought herself down to',
'</i> to the Caterpillar'],
search: searchStrings,
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
type: ['buffer', 'string'],
iter: [1]
Expand Down
24 changes: 18 additions & 6 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
'use strict';
var common = require('../common.js');

var types = [
'UInt8',
'UInt16LE',
'UInt16BE',
'UInt32LE',
'UInt32BE',
'Int8',
'Int16LE',
'Int16BE',
'Int32LE',
'Int32BE',
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE'
];

var bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: ['UInt8', 'UInt16LE', 'UInt16BE',
'UInt32LE', 'UInt32BE',
'Int8', 'Int16LE', 'Int16BE',
'Int32LE', 'Int32BE',
'FloatLE', 'FloatBE',
'DoubleLE', 'DoubleBE'],
type: types,
millions: [1]
});

Expand Down
25 changes: 19 additions & 6 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
'use strict';
var common = require('../common.js');

var types = [
'UInt8',
'UInt16LE',
'UInt16BE',
'UInt32LE',
'UInt32BE',
'Int8',
'Int16LE',
'Int16BE',
'Int32LE',
'Int32BE',
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE'
];

var bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: ['UInt8', 'UInt16LE', 'UInt16BE',
'UInt32LE', 'UInt32BE',
'Int8', 'Int16LE', 'Int16BE',
'Int32LE', 'Int32BE',
'FloatLE', 'FloatBE',
'DoubleLE', 'DoubleBE'],
type: types,
millions: [1]
});

Expand Down
25 changes: 19 additions & 6 deletions benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use strict';
var common = require('../common.js');

var types = [
'Uint8',
'Uint16LE',
'Uint16BE',
'Uint32LE',
'Uint32BE',
'Int8',
'Int16LE',
'Int16BE',
'Int32LE',
'Int32BE',
'Float32LE',
'Float32BE',
'Float64LE',
'Float64BE'
];

var bench = common.createBenchmark(main, {
type: ['Uint8', 'Uint16LE', 'Uint16BE',
'Uint32LE', 'Uint32BE',
'Int8', 'Int16LE', 'Int16BE',
'Int32LE', 'Int32BE',
'Float32LE', 'Float32BE',
'Float64LE', 'Float64BE'],
type: types,
millions: [1]
});

Expand Down
8 changes: 4 additions & 4 deletions benchmark/es/map-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function runObject(n) {
for (; i < n; i++) {
m['i' + i] = i;
m['s' + i] = String(i);
assert.equal(m['i' + i], m['s' + i]);
assert.strictEqual(String(m['i' + i]), m['s' + i]);
m['i' + i] = undefined;
m['s' + i] = undefined;
}
Expand All @@ -29,7 +29,7 @@ function runNullProtoObject(n) {
for (; i < n; i++) {
m['i' + i] = i;
m['s' + i] = String(i);
assert.equal(m['i' + i], m['s' + i]);
assert.strictEqual(String(m['i' + i]), m['s' + i]);
m['i' + i] = undefined;
m['s' + i] = undefined;
}
Expand All @@ -53,7 +53,7 @@ function runFakeMap(n) {
for (; i < n; i++) {
m.set('i' + i, i);
m.set('s' + i, String(i));
assert.equal(m.get('i' + i), m.get('s' + i));
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
m.set('i' + i, undefined);
m.set('s' + i, undefined);
}
Expand All @@ -67,7 +67,7 @@ function runMap(n) {
for (; i < n; i++) {
m.set('i' + i, i);
m.set('s' + i, String(i));
assert.equal(m.get('i' + i), m.get('s' + i));
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
m.set('i' + i, undefined);
m.set('s' + i, undefined);
}
Expand Down
7 changes: 5 additions & 2 deletions benchmark/http/http_server_for_chunky_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ try {
} catch (e) { /* ignore */ }

server = http.createServer(function(req, res) {
res.writeHead(200, { 'content-type': 'text/plain',
'content-length': '2' });
var headers = {
'content-type': 'text/plain',
'content-length': '2'
};
res.writeHead(200, headers);
res.end('ok');
});

Expand Down
22 changes: 15 additions & 7 deletions benchmark/http_simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ var server = module.exports = http.createServer(function(req, res) {
body = fixed;

} else if (command === 'echo') {
res.writeHead(200, { 'Content-Type': 'text/plain',
'Transfer-Encoding': 'chunked' });
const headers = {
'Content-Type': 'text/plain',
'Transfer-Encoding': 'chunked'
};
res.writeHead(200, headers);
req.pipe(res);
return;

Expand All @@ -88,8 +91,11 @@ var server = module.exports = http.createServer(function(req, res) {
// example: http://localhost:port/bytes/512/4
// sends a 512 byte body in 4 chunks of 128 bytes
if (n_chunks > 0) {
res.writeHead(status, { 'Content-Type': 'text/plain',
'Transfer-Encoding': 'chunked' });
const headers = {
'Content-Type': 'text/plain',
'Transfer-Encoding': 'chunked'
};
res.writeHead(status, headers);
// send body in chunks
var len = body.length;
var step = Math.floor(len / n_chunks) || 1;
Expand All @@ -99,10 +105,12 @@ var server = module.exports = http.createServer(function(req, res) {
}
res.end(body.slice((n_chunks - 1) * step));
} else {
var content_length = body.length.toString();
const headers = {
'Content-Type': 'text/plain',
'Content-Length': body.length.toString()
};

res.writeHead(status, { 'Content-Type': 'text/plain',
'Content-Length': content_length });
res.writeHead(status, headers);
res.end(body);
}
});
Expand Down
12 changes: 8 additions & 4 deletions benchmark/misc/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ const v8 = require('v8');

v8.setFlagsFromString('--allow_natives_syntax');

const methods = [
'restAndSpread',
'argumentsAndApply',
'restAndApply',
'restAndConcat'
];

var bench = common.createBenchmark(main, {
method: ['restAndSpread',
'argumentsAndApply',
'restAndApply',
'restAndConcat'],
method: methods,
concat: [1, 0],
n: [1000000]
});
Expand Down
18 changes: 11 additions & 7 deletions benchmark/querystring/querystring-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ var common = require('../common.js');
var querystring = require('querystring');
var v8 = require('v8');

var types = [
'noencode',
'multicharsep',
'encodemany',
'encodelast',
'multivalue',
'multivaluemany',
'manypairs'
];

var bench = common.createBenchmark(main, {
type: ['noencode',
'multicharsep',
'encodemany',
'encodelast',
'multivalue',
'multivaluemany',
'manypairs'],
type: types,
n: [1e6],
});

Expand Down
10 changes: 6 additions & 4 deletions benchmark/tls/throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ function main(conf) {
throw new Error('invalid type');
}

options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
ciphers: 'AES256-GCM-SHA384' };
options = {
key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
ciphers: 'AES256-GCM-SHA384'
};

server = tls.createServer(options, onConnection);
setTimeout(done, dur * 1000);
Expand Down
Loading

0 comments on commit c32c86b

Please sign in to comment.