-
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.
PR-URL: #51866 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
1 parent
f5241e2
commit 0b853a7
Showing
8 changed files
with
250 additions
and
35 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,36 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { Readable } = require('stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
kind: ['read', 'encoding'], | ||
}); | ||
const ABC = new Uint8Array([0x41, 0x42, 0x43]); | ||
|
||
function main({ n, kind }) { | ||
switch (kind) { | ||
case 'read': { | ||
bench.start(); | ||
const readable = new Readable({ | ||
read() {}, | ||
}); | ||
for (let i = 0; i < n; ++i) readable.push(ABC); | ||
bench.end(n); | ||
break; | ||
} | ||
|
||
case 'encoding': { | ||
bench.start(); | ||
const readable = new Readable({ | ||
read() {}, | ||
}); | ||
readable.setEncoding('utf8'); | ||
for (let i = 0; i < n; ++i) readable.push(ABC); | ||
bench.end(n); | ||
break; | ||
} | ||
default: | ||
throw new Error('Invalid kind'); | ||
} | ||
} |
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,51 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { Writable } = require('stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [50e6], | ||
kind: ['write', 'object-mode', 'writev'], | ||
}); | ||
const ABC = new Uint8Array([0x41, 0x42, 0x43]); | ||
|
||
function main({ n, kind }) { | ||
switch (kind) { | ||
case 'write': { | ||
bench.start(); | ||
const wr = new Writable({ | ||
write(chunk, encoding, cb) { | ||
cb(); | ||
}, | ||
}); | ||
for (let i = 0; i < n; ++i) wr.write(ABC); | ||
bench.end(n); | ||
break; | ||
} | ||
|
||
case 'object-mode': { | ||
bench.start(); | ||
const wr = new Writable({ | ||
objectMode: true, | ||
write(chunk, encoding, cb) { | ||
cb(); | ||
}, | ||
}); | ||
for (let i = 0; i < n; ++i) wr.write(ABC); | ||
bench.end(n); | ||
break; | ||
} | ||
case 'writev': { | ||
bench.start(); | ||
const wr = new Writable({ | ||
writev(chunks, cb) { | ||
cb(); | ||
}, | ||
}); | ||
for (let i = 0; i < n; ++i) wr.write(ABC); | ||
bench.end(n); | ||
break; | ||
} | ||
default: | ||
throw new Error('Invalid kind'); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.