From 0e864a383c80aa1da0937d165fcd33bdbf729dfb Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 15 Dec 2019 13:44:15 +0100 Subject: [PATCH] benchmark: update manywrites back pressure Make manywrites benchmark a bit more realistic by taking back pressure into account. Otherwise memory usage would no correspond well with real world usage. PR-URL: https://github.com/nodejs/node/pull/30977 Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Jeremiah Senkpiel Reviewed-By: Rich Trott --- benchmark/streams/writable-manywrites.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/benchmark/streams/writable-manywrites.js b/benchmark/streams/writable-manywrites.js index 0ed38d0357a438..ebd83779b76158 100644 --- a/benchmark/streams/writable-manywrites.js +++ b/benchmark/streams/writable-manywrites.js @@ -20,8 +20,13 @@ function main({ n, sync }) { }; bench.start(); - for (var k = 0; k < n; ++k) { - s.write(b); + + let k = 0; + function run() { + while (k++ < n && s.write(b)); + if (k >= n) + bench.end(n); } - bench.end(n); + s.on('drain', run); + run(); }