forked from cujojs/most
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.js
61 lines (54 loc) · 1.84 KB
/
scan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('buba/register')
var Benchmark = require('benchmark');
var most = require('../../src/index');
var rx = require('rx');
var rxjs = require('@reactivex/rxjs');
var kefir = require('kefir');
var bacon = require('baconjs');
var highland = require('highland');
var xs = require('xstream').default;
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(1000000);
var a = new Array(n);
for(var i = 0; i< a.length; ++i) {
a[i] = i;
}
var suite = Benchmark.Suite('scan -> reduce ' + n + ' integers');
var options = {
defer: true,
onError: function(e) {
e.currentTarget.failure = e.error;
}
};
suite
.add('most', function(deferred) {
runners.runMost(deferred, most.from(a).scan(sum, 0).reduce(passthrough, 0));
}, options)
.add('rx 4', function(deferred) {
runners.runRx(deferred, rx.Observable.fromArray(a).scan(sum, 0).reduce(passthrough, 0));
}, options)
.add('rx 5', function(deferred) {
runners.runRx5(deferred, rxjs.Observable.from(a).scan(sum, 0).reduce(passthrough, 0));
}, options)
.add('xstream', function(deferred) {
runners.runXstream(deferred, xs.fromArray(a).fold(sum, 0).fold(passthrough, 0).last());
}, options)
.add('kefir', function(deferred) {
runners.runKefir(deferred, kefirFromArray(a).scan(sum, 0).scan(passthrough, 0).last());
}, options)
.add('bacon', function(deferred) {
runners.runBacon(deferred, bacon.fromArray(a).scan(0, sum).reduce(0, passthrough));
}, options)
.add('highland', function(deferred) {
runners.runHighland(deferred, highland(a).scan(0, sum).reduce(0, passthrough));
}, options);
runners.runSuite(suite);
function sum(x, y) {
return x + y;
}
function passthrough(z, x) {
return x;
}