From 54f36513c6e41fc591d2960923f83b52d0858ba8 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 17 Nov 2022 09:43:24 -0500 Subject: [PATCH] benchmark: add readable stream encoding benchmark --- benchmark/streams/readable-encoding.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 benchmark/streams/readable-encoding.js diff --git a/benchmark/streams/readable-encoding.js b/benchmark/streams/readable-encoding.js new file mode 100644 index 00000000000000..e9888bc2ab7108 --- /dev/null +++ b/benchmark/streams/readable-encoding.js @@ -0,0 +1,36 @@ +'use strict'; + + const common = require('../common'); + const Readable = require('stream').Readable; + + const BASE = 'hello world\n\n'; + + const bench = common.createBenchmark(main, { + encoding: ['utf-8', 'latin1'], + len: [256, 512, 1024 * 16], + op: ['unshift', 'push'], + n: [1e3] + }); + + function main({ n, encoding, len, op }) { + const b = BASE.repeat(len); + const s = new Readable({ + objectMode: false, + }); + + bench.start(); + switch (op) { + case 'unshift': { + for (let i = 0; i < n; i++) + s.unshift(b, encoding); + break; + } + case 'push': { + for (let i = 0; i < n; i++) + s.push(b, encoding); + break; + } + } + bench.end(n); + } + \ No newline at end of file