forked from cujojs/most
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice.js
69 lines (60 loc) · 1.89 KB
/
slice.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
62
63
64
65
66
67
68
69
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('skip(n/4) -> take(n/2) ' + n + ' integers');
var options = {
defer: true,
onError: function(e) {
e.currentTarget.failure = e.error;
}
};
var s = n * 0.25;
var t = n * 0.5;
suite
.add('most', function(deferred) {
runners.runMost(deferred, most.from(a).skip(s).take(t).reduce(sum, 0));
}, options)
.add('rx 4', function(deferred) {
runners.runRx(deferred, rx.Observable.fromArray(a).skip(s).take(t).reduce(sum, 0));
}, options)
.add('rx 5', function(deferred) {
runners.runRx5(deferred,
rxjs.Observable.from(a).skip(s).take(t).reduce(sum, 0));
}, options)
.add('xstream', function(deferred) {
runners.runXstream(deferred, xs.fromArray(a).drop(s).take(t).fold(sum, 0).last());
}, options)
.add('kefir', function(deferred) {
runners.runKefir(deferred, kefirFromArray(a).skip(s).take(t).scan(sum, 0).last());
}, options)
.add('bacon', function(deferred) {
runners.runBacon(deferred, bacon.fromArray(a).skip(s).take(t).reduce(0, sum));
}, options)
.add('highland', function(deferred) {
runners.runHighland(deferred, highland(a).drop(s).take(t).reduce(0, sum));
}, options)
runners.runSuite(suite);
function add1(x) {
return x + 1;
}
function even(x) {
return x % 2 === 0;
}
function sum(x, y) {
return x + y;
}