https://github.com/missinglink/through2-benchmark
simple benchmarking to check the performance of a through2 stream
https://github.com/missinglink/through2-benchmark
Last synced: over 1 year ago
JSON representation
simple benchmarking to check the performance of a through2 stream
- Host: GitHub
- URL: https://github.com/missinglink/through2-benchmark
- Owner: missinglink
- License: mit
- Created: 2017-07-13T12:37:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-13T12:38:41.000Z (almost 9 years ago)
- Last Synced: 2025-01-22T08:11:20.976Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Disclaimer
This module was written quick 'n dirty, it currently doesn't have tests and the API will probably change over time.
## Installation
```bash
$ npm install through2-benchmark
```
[](https://nodei.co/npm/through2-benchmark)
## Example
```javascript
// copied from example.js
var through = require('through2'),
benchmark = require('through2-benchmark');
function createDelayStream( delay ){
return through.obj( function( chunk, enc, next ){
setTimeout( function(){
this.push( chunk );
this.push( chunk );
next();
}.bind(this), delay );
});
}
var streams = {
stream1: createDelayStream(200),
stream2: createDelayStream(100),
tap: through.obj(),
sink: through.obj( function( _, __, next ){ next(); })
};
streams.tap
.pipe( benchmark.proxy( 'stream1', streams.stream1 ) )
.pipe( benchmark.proxy( 'stream2', streams.stream2 ) )
.pipe( benchmark.proxy( 'sink', streams.sink ) );
for( var i=0; i<10; i++ ){
streams.tap.write({ hello: 'world' });
}
streams.tap.end();
```
```bash
$ node example.js
[stream1] processed 10 records in 2015.7093 ms
[stream1] average speed 201.5709 ms
[stream2] processed 20 records in 2025.5596 ms
[stream2] average speed 101.278 ms
[sink] processed 40 records in 0.8005 ms
[sink] average speed 0.02 ms
```