Skip to content

Commit

Permalink
benchmark: clean up config resolution in multiple benchmarks
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lundibundi authored and Trott committed Feb 3, 2020
1 parent dbaa4ca commit f7a1ef6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 26 deletions.
8 changes: 3 additions & 5 deletions benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const bench = common.createBenchmark(main, {
concurrent: [1, 10]
});

function main(conf) {
const len = +conf.len;
function main({ len, dur, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
Expand All @@ -40,7 +39,7 @@ function main(conf) {
benchEnded = true;
bench.end(totalOps);
try { fs.unlinkSync(filename); } catch {}
}, +conf.dur * 1000);
}, dur * 1000);

function read() {
fs.readFile(filename, afterRead);
Expand Down Expand Up @@ -78,8 +77,7 @@ function main(conf) {
}

// Start reads
let cur = +conf.concurrent;
while (cur--) read();
while (concurrent-- > 0) read();

// Start a competing zip
zip();
Expand Down
5 changes: 1 addition & 4 deletions benchmark/http/set_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const bench = common.createBenchmark(main, {
n: [1e6],
});

function main(conf) {
const n = +conf.n;
const value = conf.value;

function main({ n, value }) {
const og = new OutgoingMessage();

bench.start();
Expand Down
5 changes: 2 additions & 3 deletions benchmark/url/legacy-vs-whatwg-url-get-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ function useWHATWG(data) {
}

function main({ type, method, e }) {
e = +e;
var data;
var noDead; // Avoid dead code elimination.
let data;
let noDead; // Avoid dead code elimination.
switch (method) {
case 'legacy':
data = common.bakeUrlData(type, e, false, false);
Expand Down
1 change: 0 additions & 1 deletion benchmark/url/legacy-vs-whatwg-url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function useWHATWGWithoutBase(data) {
}

function main({ e, method, type, withBase }) {
e = +e;
withBase = withBase === 'true';
var noDead; // Avoid dead code elimination.
var data;
Expand Down
1 change: 0 additions & 1 deletion benchmark/url/legacy-vs-whatwg-url-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function useWHATWG(data) {
}

function main({ type, e, method }) {
e = +e;
const data = common.bakeUrlData(type, e, false, false);

var noDead; // Avoid dead code elimination.
Expand Down
1 change: 0 additions & 1 deletion benchmark/url/whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function get(data, prop) {
}

function main({ e, type, prop, withBase }) {
e = +e;
withBase = withBase === 'true';
const data = common.bakeUrlData(type, e, withBase, true);
switch (prop) {
Expand Down
18 changes: 7 additions & 11 deletions benchmark/worker/echo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

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

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

function main(conf) {
const { Worker } = require('worker_threads');

const n = +conf.n;
const workers = +conf.workers;
const sends = +conf.sendsPerBroadcast;
function main({ n, workers, sendsPerBroadcast: sends, payload: payloadType }) {
const expectedPerBroadcast = sends * workers;
var payload;
var readies = 0;
var broadcasts = 0;
var msgCount = 0;
let payload;
let readies = 0;
let broadcasts = 0;
let msgCount = 0;

switch (conf.payload) {
switch (payloadType) {
case 'string':
payload = 'hello world!';
break;
Expand Down

0 comments on commit f7a1ef6

Please sign in to comment.