-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(combine): apply some perf optimizations to combine
Inspired by some ideas in PR #14.
- Loading branch information
Showing
2 changed files
with
98 additions
and
34 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,72 @@ | ||
var Benchmark = require('benchmark'); | ||
var xs = require('../index').default; | ||
var most = require('most'); | ||
var rx = require('rx'); | ||
var rxjs = require('@reactivex/rxjs') | ||
var kefir = require('kefir'); | ||
var bacon = require('baconjs'); | ||
var lodash = require('lodash'); | ||
var highland = require('highland'); | ||
|
||
var runners = require('./runners'); | ||
var kefirFromArray = runners.kefirFromArray; | ||
|
||
// Create a stream from an Array of n integers | ||
// filter out odds, map remaining evens by adding 1, then reduce by summing | ||
var n = runners.getIntArg(500000); | ||
var a = new Array(n); | ||
for(var i = 0; i< a.length; ++i) { | ||
a[i] = i; | ||
} | ||
|
||
var suite = Benchmark.Suite('combine(add3) -> filter ' + n + ' x 3 integers'); | ||
var options = { | ||
defer: true, | ||
onError: function(e) { | ||
e.currentTarget.failure = e.error; | ||
} | ||
}; | ||
|
||
function add3(a, b, c) { | ||
return a + b + c; | ||
} | ||
|
||
var xs1 = xs.fromArray(a); | ||
var xs2 = xs.fromArray(a); | ||
var xs3 = xs.fromArray(a); | ||
|
||
var m1 = most.from(a); | ||
var m2 = most.from(a); | ||
var m3 = most.from(a); | ||
|
||
var rx1 = rxjs.Observable.from(a); | ||
var rx2 = rxjs.Observable.from(a); | ||
var rx3 = rxjs.Observable.from(a); | ||
|
||
suite | ||
.add('xstream', function(deferred) { | ||
runners.runXStream(deferred, | ||
xs.combine(add3, xs1, xs2, xs3).filter(even)); | ||
}, options) | ||
.add('most', function(deferred) { | ||
runners.runMost(deferred, | ||
most.combineArray(add3, [m1, m2, m3]).filter(even).drain()); | ||
}, options) | ||
.add('rx 5', function(deferred) { | ||
runners.runRx5(deferred, | ||
rxjs.Observable.combineLatest(rx1, rx2, rx3, add3).filter(even)); | ||
}, options); | ||
|
||
runners.runSuite(suite); | ||
|
||
function add1(x) { | ||
return x + 1; | ||
} | ||
|
||
function even(x) { | ||
return x % 2 === 0; | ||
} | ||
|
||
function sum(x, y) { | ||
return x + y; | ||
} |
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