From b06f8fe0b96449f85d5ad50d77980a63c45865ca Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 15 Dec 2019 13:44:15 +0100 Subject: [PATCH] benchmark: 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. --- 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(); }