Skip to content

Commit 9c12582

Browse files
BridgeARMylesBorins
authored andcommitted
benchmark: refactor
PR-URL: #18320 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f018670 commit 9c12582

17 files changed

+39
-82
lines changed

benchmark/async_hooks/gc-tracking.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ function endAfterGC(n) {
2222
}
2323

2424
function main({ n, method }) {
25+
var i;
2526
switch (method) {
2627
case 'trackingEnabled':
2728
bench.start();
28-
for (let i = 0; i < n; i++) {
29+
for (i = 0; i < n; i++) {
2930
new AsyncResource('foobar');
3031
}
3132
endAfterGC(n);
3233
break;
3334
case 'trackingDisabled':
3435
bench.start();
35-
for (let i = 0; i < n; i++) {
36+
for (i = 0; i < n; i++) {
3637
new AsyncResource('foobar', { requireManualDestroy: true });
3738
}
3839
endAfterGC(n);
3940
break;
4041
default:
41-
throw new Error('Unsupported method');
42+
throw new Error(`Unsupported method "${method}"`);
4243
}
4344
}

benchmark/dgram/bind-params.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ const noop = () => {};
1515
function main({ n, port, address }) {
1616
port = port === 'true' ? 0 : undefined;
1717
address = address === 'true' ? '0.0.0.0' : undefined;
18+
var i;
1819

1920
if (port !== undefined && address !== undefined) {
2021
bench.start();
21-
for (let i = 0; i < n; i++) {
22+
for (i = 0; i < n; i++) {
2223
dgram.createSocket('udp4').bind(port, address)
2324
.on('error', noop)
2425
.unref();
2526
}
2627
bench.end(n);
2728
} else if (port !== undefined) {
2829
bench.start();
29-
for (let i = 0; i < n; i++) {
30+
for (i = 0; i < n; i++) {
3031
dgram.createSocket('udp4')
3132
.bind(port)
3233
.on('error', noop)
@@ -35,7 +36,7 @@ function main({ n, port, address }) {
3536
bench.end(n);
3637
} else if (port === undefined && address === undefined) {
3738
bench.start();
38-
for (let i = 0; i < n; i++) {
39+
for (i = 0; i < n; i++) {
3940
dgram.createSocket('udp4')
4041
.bind()
4142
.on('error', noop)

benchmark/domain/domain-fn-args.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ function main({ n, args }) {
2828
bench.end(n);
2929
}
3030

31-
function fn(a, b, c) {
32-
if (!a)
33-
a = 1;
34-
35-
if (!b)
36-
b = 2;
37-
38-
if (!c)
39-
c = 3;
40-
31+
function fn(a = 1, b = 2, c = 3) {
4132
return a + b + c;
4233
}

benchmark/fs/bench-realpath.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ function main({ n, pathType }) {
1616
bench.start();
1717
if (pathType === 'relative')
1818
relativePath(n);
19-
else if (pathType === 'resolved')
20-
resolvedPath(n);
2119
else
22-
throw new Error(`unknown "pathType": ${pathType}`);
20+
resolvedPath(n);
2321
}
2422

2523
function relativePath(n) {

benchmark/fs/bench-realpathSync.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,10 @@ const bench = common.createBenchmark(main, {
1515

1616

1717
function main({ n, pathType }) {
18+
const path = pathType === 'relative' ? relative_path : resolved_path;
1819
bench.start();
19-
if (pathType === 'relative')
20-
relativePath(n);
21-
else if (pathType === 'resolved')
22-
resolvedPath(n);
23-
else
24-
throw new Error(`unknown "pathType": ${pathType}`);
25-
bench.end(n);
26-
}
27-
28-
function relativePath(n) {
29-
for (var i = 0; i < n; i++) {
30-
fs.realpathSync(relative_path);
31-
}
32-
}
33-
34-
function resolvedPath(n) {
3520
for (var i = 0; i < n; i++) {
36-
fs.realpathSync(resolved_path);
21+
fs.realpathSync(path);
3722
}
23+
bench.end(n);
3824
}

benchmark/fs/write-stream-throughput.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function main({ dur, encodingType, size }) {
3636
try { fs.unlinkSync(filename); } catch (e) {}
3737

3838
var started = false;
39-
var ending = false;
4039
var ended = false;
4140

4241
var f = fs.createWriteStream(filename);
@@ -52,15 +51,9 @@ function main({ dur, encodingType, size }) {
5251

5352

5453
function write() {
55-
// don't try to write after we end, even if a 'drain' event comes.
56-
// v0.8 streams are so sloppy!
57-
if (ending)
58-
return;
59-
6054
if (!started) {
6155
started = true;
6256
setTimeout(function() {
63-
ending = true;
6457
f.end();
6558
}, dur * 1000);
6659
bench.start();

benchmark/misc/freelist.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function main({ n }) {
1212
const FreeList = require('internal/freelist');
1313
const poolSize = 1000;
1414
const list = new FreeList('test', poolSize, Object);
15-
var i;
1615
var j;
1716
const used = [];
1817

@@ -23,7 +22,7 @@ function main({ n }) {
2322

2423
bench.start();
2524

26-
for (i = 0; i < n; i++) {
25+
for (var i = 0; i < n; i++) {
2726
// Return all the items to the pool
2827
for (j = 0; j < poolSize; j++) {
2928
list.free(used[j]);

benchmark/misc/function_call/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ const bench = common.createBenchmark(main, {
3232
});
3333

3434
function main({ millions, type }) {
35-
const n = millions * 1e6;
36-
3735
const fn = type === 'cxx' ? cxx : js;
3836
bench.start();
39-
for (var i = 0; i < n; i++) {
37+
for (var i = 0; i < millions * 1e6; i++) {
4038
fn();
4139
}
4240
bench.end(millions);

benchmark/misc/object-property-bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ function main({ millions, method }) {
7878
runSymbol(n);
7979
break;
8080
default:
81-
throw new Error('Unexpected method');
81+
throw new Error(`Unexpected method "${method}"`);
8282
}
8383
}

benchmark/misc/punycode.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ function runPunycode(n, val) {
5555
}
5656

5757
function runICU(n, val) {
58-
var i = 0;
5958
bench.start();
60-
for (; i < n; i++)
59+
for (var i = 0; i < n; i++)
6160
usingICU(val);
6261
bench.end(n);
6362
}
@@ -76,6 +75,6 @@ function main({ n, val, method }) {
7675
}
7776
// fallthrough
7877
default:
79-
throw new Error('Unexpected method');
78+
throw new Error(`Unexpected method "${method}"`);
8079
}
8180
}

0 commit comments

Comments
 (0)