Skip to content

Commit c32c86b

Browse files
TrottMylesBorins
authored andcommitted
benchmark: reformat code for clarity
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]>
1 parent e94b72e commit c32c86b

16 files changed

+190
-73
lines changed

benchmark/arrays/var-int.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use strict';
22
var common = require('../common.js');
3+
4+
var types = [
5+
'Array',
6+
'Buffer',
7+
'Int8Array',
8+
'Uint8Array',
9+
'Int16Array',
10+
'Uint16Array',
11+
'Int32Array',
12+
'Uint32Array',
13+
'Float32Array',
14+
'Float64Array'
15+
];
16+
317
var bench = common.createBenchmark(main, {
4-
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
5-
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
6-
'Float64Array'],
18+
type: types,
719
n: [25]
820
});
921

benchmark/arrays/zero-float.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use strict';
22
var common = require('../common.js');
3+
4+
var types = [
5+
'Array',
6+
'Buffer',
7+
'Int8Array',
8+
'Uint8Array',
9+
'Int16Array',
10+
'Uint16Array',
11+
'Int32Array',
12+
'Uint32Array',
13+
'Float32Array',
14+
'Float64Array'
15+
];
16+
317
var bench = common.createBenchmark(main, {
4-
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
5-
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
6-
'Float64Array'],
18+
type: types,
719
n: [25]
820
});
921

benchmark/arrays/zero-int.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use strict';
22
var common = require('../common.js');
3+
4+
var types = [
5+
'Array',
6+
'Buffer',
7+
'Int8Array',
8+
'Uint8Array',
9+
'Int16Array',
10+
'Uint16Array',
11+
'Int32Array',
12+
'Uint32Array',
13+
'Float32Array',
14+
'Float64Array'
15+
];
16+
317
var bench = common.createBenchmark(main, {
4-
type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array',
5-
'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array',
6-
'Float64Array'],
18+
type: types,
719
n: [25]
820
});
921

benchmark/buffers/buffer-base64-decode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const bench = common.createBenchmark(main, {});
77
function main(conf) {
88
const s = 'abcd'.repeat(8 << 20);
99
s.match(/./); // Flatten string.
10-
assert.equal(s.length % 4, 0);
10+
assert.strictEqual(s.length % 4, 0);
1111
const b = Buffer.allocUnsafe(s.length / 4 * 3);
1212
b.write(s, 0, s.length, 'base64');
1313
bench.start();

benchmark/buffers/buffer-indexof.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ var common = require('../common.js');
33
var fs = require('fs');
44
const path = require('path');
55

6+
const searchStrings = [
7+
'@',
8+
'SQ',
9+
'10x',
10+
'--l',
11+
'Alice',
12+
'Gryphon',
13+
'Panther',
14+
'Ou est ma chatte?',
15+
'found it very',
16+
'among mad people',
17+
'neighbouring pool',
18+
'Soo--oop',
19+
'aaaaaaaaaaaaaaaaa',
20+
'venture to go near the house till she had brought herself down to',
21+
'</i> to the Caterpillar'
22+
];
23+
624
var bench = common.createBenchmark(main, {
7-
search: ['@', 'SQ', '10x', '--l', 'Alice', 'Gryphon', 'Panther',
8-
'Ou est ma chatte?', 'found it very', 'among mad people',
9-
'neighbouring pool', 'Soo--oop', 'aaaaaaaaaaaaaaaaa',
10-
'venture to go near the house till she had brought herself down to',
11-
'</i> to the Caterpillar'],
25+
search: searchStrings,
1226
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
1327
type: ['buffer', 'string'],
1428
iter: [1]

benchmark/buffers/buffer-read.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
'use strict';
22
var common = require('../common.js');
33

4+
var types = [
5+
'UInt8',
6+
'UInt16LE',
7+
'UInt16BE',
8+
'UInt32LE',
9+
'UInt32BE',
10+
'Int8',
11+
'Int16LE',
12+
'Int16BE',
13+
'Int32LE',
14+
'Int32BE',
15+
'FloatLE',
16+
'FloatBE',
17+
'DoubleLE',
18+
'DoubleBE'
19+
];
20+
421
var bench = common.createBenchmark(main, {
522
noAssert: ['false', 'true'],
623
buffer: ['fast', 'slow'],
7-
type: ['UInt8', 'UInt16LE', 'UInt16BE',
8-
'UInt32LE', 'UInt32BE',
9-
'Int8', 'Int16LE', 'Int16BE',
10-
'Int32LE', 'Int32BE',
11-
'FloatLE', 'FloatBE',
12-
'DoubleLE', 'DoubleBE'],
24+
type: types,
1325
millions: [1]
1426
});
1527

benchmark/buffers/buffer-write.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
'use strict';
22
var common = require('../common.js');
3+
4+
var types = [
5+
'UInt8',
6+
'UInt16LE',
7+
'UInt16BE',
8+
'UInt32LE',
9+
'UInt32BE',
10+
'Int8',
11+
'Int16LE',
12+
'Int16BE',
13+
'Int32LE',
14+
'Int32BE',
15+
'FloatLE',
16+
'FloatBE',
17+
'DoubleLE',
18+
'DoubleBE'
19+
];
20+
321
var bench = common.createBenchmark(main, {
422
noAssert: ['false', 'true'],
523
buffer: ['fast', 'slow'],
6-
type: ['UInt8', 'UInt16LE', 'UInt16BE',
7-
'UInt32LE', 'UInt32BE',
8-
'Int8', 'Int16LE', 'Int16BE',
9-
'Int32LE', 'Int32BE',
10-
'FloatLE', 'FloatBE',
11-
'DoubleLE', 'DoubleBE'],
24+
type: types,
1225
millions: [1]
1326
});
1427

benchmark/buffers/dataview-set.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
'use strict';
22
var common = require('../common.js');
3+
4+
var types = [
5+
'Uint8',
6+
'Uint16LE',
7+
'Uint16BE',
8+
'Uint32LE',
9+
'Uint32BE',
10+
'Int8',
11+
'Int16LE',
12+
'Int16BE',
13+
'Int32LE',
14+
'Int32BE',
15+
'Float32LE',
16+
'Float32BE',
17+
'Float64LE',
18+
'Float64BE'
19+
];
20+
321
var bench = common.createBenchmark(main, {
4-
type: ['Uint8', 'Uint16LE', 'Uint16BE',
5-
'Uint32LE', 'Uint32BE',
6-
'Int8', 'Int16LE', 'Int16BE',
7-
'Int32LE', 'Int32BE',
8-
'Float32LE', 'Float32BE',
9-
'Float64LE', 'Float64BE'],
22+
type: types,
1023
millions: [1]
1124
});
1225

benchmark/es/map-bench.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function runObject(n) {
1515
for (; i < n; i++) {
1616
m['i' + i] = i;
1717
m['s' + i] = String(i);
18-
assert.equal(m['i' + i], m['s' + i]);
18+
assert.strictEqual(String(m['i' + i]), m['s' + i]);
1919
m['i' + i] = undefined;
2020
m['s' + i] = undefined;
2121
}
@@ -29,7 +29,7 @@ function runNullProtoObject(n) {
2929
for (; i < n; i++) {
3030
m['i' + i] = i;
3131
m['s' + i] = String(i);
32-
assert.equal(m['i' + i], m['s' + i]);
32+
assert.strictEqual(String(m['i' + i]), m['s' + i]);
3333
m['i' + i] = undefined;
3434
m['s' + i] = undefined;
3535
}
@@ -53,7 +53,7 @@ function runFakeMap(n) {
5353
for (; i < n; i++) {
5454
m.set('i' + i, i);
5555
m.set('s' + i, String(i));
56-
assert.equal(m.get('i' + i), m.get('s' + i));
56+
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
5757
m.set('i' + i, undefined);
5858
m.set('s' + i, undefined);
5959
}
@@ -67,7 +67,7 @@ function runMap(n) {
6767
for (; i < n; i++) {
6868
m.set('i' + i, i);
6969
m.set('s' + i, String(i));
70-
assert.equal(m.get('i' + i), m.get('s' + i));
70+
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
7171
m.set('i' + i, undefined);
7272
m.set('s' + i, undefined);
7373
}

benchmark/http/http_server_for_chunky_client.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ try {
2121
} catch (e) { /* ignore */ }
2222

2323
server = http.createServer(function(req, res) {
24-
res.writeHead(200, { 'content-type': 'text/plain',
25-
'content-length': '2' });
24+
var headers = {
25+
'content-type': 'text/plain',
26+
'content-length': '2'
27+
};
28+
res.writeHead(200, headers);
2629
res.end('ok');
2730
});
2831

0 commit comments

Comments
 (0)