From f7a1ef6fb51f814223e3c26fffb9d39b08f91b1b Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Thu, 30 Jan 2020 19:08:38 +0200 Subject: [PATCH] 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 Reviewed-By: Rich Trott --- benchmark/fs/readfile-partitioned.js | 8 +++----- benchmark/http/set_header.js | 5 +---- benchmark/url/legacy-vs-whatwg-url-get-prop.js | 5 ++--- benchmark/url/legacy-vs-whatwg-url-parse.js | 1 - .../url/legacy-vs-whatwg-url-serialize.js | 1 - benchmark/url/whatwg-url-properties.js | 1 - benchmark/worker/echo.js | 18 +++++++----------- 7 files changed, 13 insertions(+), 26 deletions(-) diff --git a/benchmark/fs/readfile-partitioned.js b/benchmark/fs/readfile-partitioned.js index 5f452319b4d28f..51700cfd649dfd 100644 --- a/benchmark/fs/readfile-partitioned.js +++ b/benchmark/fs/readfile-partitioned.js @@ -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(); diff --git a/benchmark/http/set_header.js b/benchmark/http/set_header.js index 470d4b008187bc..f2236696f1c7df 100644 --- a/benchmark/http/set_header.js +++ b/benchmark/http/set_header.js @@ -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(); diff --git a/benchmark/url/legacy-vs-whatwg-url-get-prop.js b/benchmark/url/legacy-vs-whatwg-url-get-prop.js index 16bcd226324ef8..fe0c464f52b3c9 100644 --- a/benchmark/url/legacy-vs-whatwg-url-get-prop.js +++ b/benchmark/url/legacy-vs-whatwg-url-get-prop.js @@ -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); diff --git a/benchmark/url/legacy-vs-whatwg-url-parse.js b/benchmark/url/legacy-vs-whatwg-url-parse.js index 7c49654b47d8e2..6e5e25d231242f 100644 --- a/benchmark/url/legacy-vs-whatwg-url-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-parse.js @@ -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; diff --git a/benchmark/url/legacy-vs-whatwg-url-serialize.js b/benchmark/url/legacy-vs-whatwg-url-serialize.js index d6d8c8a4e71152..5523e549ceb233 100644 --- a/benchmark/url/legacy-vs-whatwg-url-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-serialize.js @@ -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. diff --git a/benchmark/url/whatwg-url-properties.js b/benchmark/url/whatwg-url-properties.js index 60f573e27a8fe2..ac71ff4f636d66 100644 --- a/benchmark/url/whatwg-url-properties.js +++ b/benchmark/url/whatwg-url-properties.js @@ -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) { diff --git a/benchmark/worker/echo.js b/benchmark/worker/echo.js index 3e729d0e26fa04..60a81f0712c4c0 100644 --- a/benchmark/worker/echo.js +++ b/benchmark/worker/echo.js @@ -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;