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: https://github.com/nodejs/node/pull/31581
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Denys Otrishko
2020-01-30 19:08:38 +02:00
committed by Rich Trott
parent dbaa4ca166
commit f7a1ef6fb5
7 changed files with 13 additions and 26 deletions

View File

@@ -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);
@@ -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);
@@ -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();

View File

@@ -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();

View File

@@ -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);

View File

@@ -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;

View File

@@ -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.

View File

@@ -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) {

View File

@@ -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],
@@ -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;