Skip to content

Commit 7f828a4

Browse files
lundibundicodebytere
authored andcommittedMar 30, 2020
benchmark: clean up config resolution in multiple benchmarks
This removes 'to Number' casting in multiple benchmarks (which is handled by the benchmark runner) and cleans up some var usage in changed benchmarks. PR-URL: #31581 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 944f1a3 commit 7f828a4

7 files changed

+13
-26
lines changed
 

‎benchmark/fs/readfile-partitioned.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ const bench = common.createBenchmark(main, {
2222
concurrent: [1, 10]
2323
});
2424

25-
function main(conf) {
26-
const len = +conf.len;
25+
function main({ len, dur, concurrent }) {
2726
try { fs.unlinkSync(filename); } catch {}
2827
let data = Buffer.alloc(len, 'x');
2928
fs.writeFileSync(filename, data);
@@ -40,7 +39,7 @@ function main(conf) {
4039
benchEnded = true;
4140
bench.end(totalOps);
4241
try { fs.unlinkSync(filename); } catch {}
43-
}, +conf.dur * 1000);
42+
}, dur * 1000);
4443

4544
function read() {
4645
fs.readFile(filename, afterRead);
@@ -78,8 +77,7 @@ function main(conf) {
7877
}
7978

8079
// Start reads
81-
let cur = +conf.concurrent;
82-
while (cur--) read();
80+
while (concurrent-- > 0) read();
8381

8482
// Start a competing zip
8583
zip();

‎benchmark/http/set_header.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ const bench = common.createBenchmark(main, {
1616
n: [1e6],
1717
});
1818

19-
function main(conf) {
20-
const n = +conf.n;
21-
const value = conf.value;
22-
19+
function main({ n, value }) {
2320
const og = new OutgoingMessage();
2421

2522
bench.start();

‎benchmark/url/legacy-vs-whatwg-url-get-prop.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ function useWHATWG(data) {
7171
}
7272

7373
function main({ type, method, e }) {
74-
e = +e;
75-
var data;
76-
var noDead; // Avoid dead code elimination.
74+
let data;
75+
let noDead; // Avoid dead code elimination.
7776
switch (method) {
7877
case 'legacy':
7978
data = common.bakeUrlData(type, e, false, false);

‎benchmark/url/legacy-vs-whatwg-url-parse.js

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function useWHATWGWithoutBase(data) {
4646
}
4747

4848
function main({ e, method, type, withBase }) {
49-
e = +e;
5049
withBase = withBase === 'true';
5150
var noDead; // Avoid dead code elimination.
5251
var data;

‎benchmark/url/legacy-vs-whatwg-url-serialize.js

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function useWHATWG(data) {
3535
}
3636

3737
function main({ type, e, method }) {
38-
e = +e;
3938
const data = common.bakeUrlData(type, e, false, false);
4039

4140
var noDead; // Avoid dead code elimination.

‎benchmark/url/whatwg-url-properties.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function get(data, prop) {
3434
}
3535

3636
function main({ e, type, prop, withBase }) {
37-
e = +e;
3837
withBase = withBase === 'true';
3938
const data = common.bakeUrlData(type, e, withBase, true);
4039
switch (prop) {

‎benchmark/worker/echo.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4+
const { Worker } = require('worker_threads');
45
const path = require('path');
56
const bench = common.createBenchmark(main, {
67
workers: [1],
@@ -11,19 +12,14 @@ const bench = common.createBenchmark(main, {
1112

1213
const workerPath = path.resolve(__dirname, '..', 'fixtures', 'echo.worker.js');
1314

14-
function main(conf) {
15-
const { Worker } = require('worker_threads');
16-
17-
const n = +conf.n;
18-
const workers = +conf.workers;
19-
const sends = +conf.sendsPerBroadcast;
15+
function main({ n, workers, sendsPerBroadcast: sends, payload: payloadType }) {
2016
const expectedPerBroadcast = sends * workers;
21-
var payload;
22-
var readies = 0;
23-
var broadcasts = 0;
24-
var msgCount = 0;
17+
let payload;
18+
let readies = 0;
19+
let broadcasts = 0;
20+
let msgCount = 0;
2521

26-
switch (conf.payload) {
22+
switch (payloadType) {
2723
case 'string':
2824
payload = 'hello world!';
2925
break;

0 commit comments

Comments
 (0)
Please sign in to comment.