From d13d900eee71317836fc1918ddebfb915480773e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Dec 2017 03:57:31 +0100 Subject: [PATCH] benchmark: (http2) use destructuring PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/http2/headers.js | 4 +--- benchmark/http2/respond-with-fd.js | 14 +++++--------- benchmark/http2/simple.js | 13 +++++-------- benchmark/http2/write.js | 13 +++++-------- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/benchmark/http2/headers.js b/benchmark/http2/headers.js index 3c8d0465acb0d0..ad1eb50007a92d 100644 --- a/benchmark/http2/headers.js +++ b/benchmark/http2/headers.js @@ -9,9 +9,7 @@ const bench = common.createBenchmark(main, { benchmarker: ['h2load'] }, { flags: ['--no-warnings', '--expose-http2'] }); -function main(conf) { - const n = +conf.n; - const nheaders = +conf.nheaders; +function main({ n, nheaders }) { const http2 = require('http2'); const server = http2.createServer({ maxHeaderListPairs: 20000 diff --git a/benchmark/http2/respond-with-fd.js b/benchmark/http2/respond-with-fd.js index 791e5f3d1e7da6..6076cf91be9d84 100644 --- a/benchmark/http2/respond-with-fd.js +++ b/benchmark/http2/respond-with-fd.js @@ -14,15 +14,11 @@ const bench = common.createBenchmark(main, { benchmarker: ['h2load'] }, { flags: ['--no-warnings', '--expose-http2'] }); -function main(conf) { - +function main({ requests, streams, clients }) { fs.open(file, 'r', (err, fd) => { if (err) throw err; - const n = +conf.requests; - const m = +conf.streams; - const c = +conf.clients; const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream) => { @@ -32,10 +28,10 @@ function main(conf) { server.listen(PORT, () => { bench.http({ path: '/', - requests: n, - maxConcurrentStreams: m, - clients: c, - threads: c + requests, + maxConcurrentStreams: streams, + clients, + threads: clients }, () => server.close()); }); diff --git a/benchmark/http2/simple.js b/benchmark/http2/simple.js index e8cb3ddee2dff8..37c78d340181a8 100644 --- a/benchmark/http2/simple.js +++ b/benchmark/http2/simple.js @@ -15,10 +15,7 @@ const bench = common.createBenchmark(main, { benchmarker: ['h2load'] }, { flags: ['--no-warnings', '--expose-http2'] }); -function main(conf) { - const n = +conf.requests; - const m = +conf.streams; - const c = +conf.clients; +function main({ requests, streams, clients }) { const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream) => { @@ -30,10 +27,10 @@ function main(conf) { server.listen(PORT, () => { bench.http({ path: '/', - requests: n, - maxConcurrentStreams: m, - clients: c, - threads: c + requests, + maxConcurrentStreams: streams, + clients, + threads: clients }, () => { server.close(); }); }); } diff --git a/benchmark/http2/write.js b/benchmark/http2/write.js index 91b9c8f0c5c073..7a802ef84fd9ed 100644 --- a/benchmark/http2/write.js +++ b/benchmark/http2/write.js @@ -10,19 +10,16 @@ const bench = common.createBenchmark(main, { benchmarker: ['h2load'] }, { flags: ['--no-warnings', '--expose-http2'] }); -function main(conf) { - const m = +conf.streams; - const l = +conf.length; - const s = +conf.size; +function main({ streams, length, size }) { const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream) => { stream.respond(); let written = 0; function write() { - stream.write('ü'.repeat(s)); - written += s; - if (written < l) + stream.write('ü'.repeat(size)); + written += size; + if (written < length) setImmediate(write); else stream.end(); @@ -33,7 +30,7 @@ function main(conf) { bench.http({ path: '/', requests: 10000, - maxConcurrentStreams: m, + maxConcurrentStreams: streams, }, () => { server.close(); }); }); }