-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add stream.pipe benchmarks
PR-URL: #18617 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Benedikt Meurer <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { Readable, Writable } = require('stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [5e6] | ||
}); | ||
|
||
function main({ n }) { | ||
const b = {}; | ||
const r = new Readable({ objectMode: true }); | ||
const w = new Writable({ objectMode: true }); | ||
|
||
var i = 0; | ||
|
||
r._read = () => r.push(i++ === n ? null : b); | ||
w._write = (data, enc, cb) => cb(); | ||
|
||
bench.start(); | ||
|
||
r.pipe(w); | ||
w.on('finish', () => bench.end(n)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { Readable, Writable } = require('stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [5e6] | ||
}); | ||
|
||
function main({ n }) { | ||
const b = new Buffer(1024); | ||
const r = new Readable(); | ||
const w = new Writable(); | ||
|
||
var i = 0; | ||
|
||
r._read = () => r.push(i++ === n ? null : b); | ||
w._write = (data, enc, cb) => cb(); | ||
|
||
bench.start(); | ||
|
||
r.pipe(w); | ||
w.on('finish', () => bench.end(n)); | ||
} |