Created
June 19, 2017 14:45
-
-
Save mrkmg/85e209e7d863166624f980e088b23772 to your computer and use it in GitHub Desktop.
Stream Beans Performance Testing
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
const Benchmark = require('benchmark'); | |
const {PassThrough} = require("stream"); | |
const createStreamBeans = require("streambeans").createStreamBeans; | |
const suite = new Benchmark.Suite(); | |
const inStreamBeans = new PassThrough(); | |
const outStreamBeans = new PassThrough(); | |
const inStreamNoBeans = new PassThrough(); | |
const outStreamNoBeans = new PassThrough(); | |
const beans = createStreamBeans(inStreamBeans, outStreamBeans); | |
inStreamNoBeans.pipe(outStreamNoBeans); | |
function withoutBeansCallback(d) { | |
outStreamNoBeans.once("data", () => d.resolve()); | |
inStreamNoBeans.write("0"); | |
} | |
function withBeansCallback(d) { | |
outStreamBeans.once("data", () => d.resolve()); | |
inStreamBeans.write("0"); | |
} | |
// add tests | |
suite | |
.add('Without StreamBeans', withoutBeansCallback, {defer: true}) | |
.add('With StreamBeans', withBeansCallback, {defer: true}) | |
// add listeners | |
.on('cycle', function (event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
// run async | |
.run({async: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment