Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 25cac21

Browse files
Adding switch perf tests
1 parent ad356e9 commit 25cac21

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/perf/operators/switch.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var RxOld = require('../old/rx.lite');
2+
var RxNew = require('../../../dist/rx.lite');
3+
var Benchmark = require('benchmark');
4+
5+
var suite = new Benchmark.Suite;
6+
7+
// Backfill range to get rid of differences
8+
RxOld.range = function (start, count) {
9+
var scheduler = RxNew.Scheduler.currentThread;
10+
return new RxNew.AnonymousObservable(function (observer) {
11+
return scheduler.scheduleRecursiveWithState(0, function (i, self) {
12+
if (i < count) {
13+
observer.onNext(start + i);
14+
self(i + 1);
15+
} else {
16+
observer.onCompleted();
17+
}
18+
});
19+
});
20+
};
21+
RxNew.range = RxOld.range;
22+
23+
// add tests
24+
suite.add('old', function() {
25+
RxOld.Observable.range(0, 50)
26+
.map(function (x) { return RxOld.Observable.range(x, 50)})
27+
.switch()
28+
.subscribe();
29+
})
30+
.add('new', function() {
31+
RxNew.Observable.range(0, 50)
32+
.map(function (x) { return RxNew.Observable.range(x, 50)})
33+
.switch()
34+
.subscribe();
35+
})
36+
// add listeners
37+
.on('cycle', function(event) {
38+
console.log(String(event.target));
39+
})
40+
.on('complete', function() {
41+
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
42+
})
43+
// run async
44+
.run({ 'async': true });

0 commit comments

Comments
 (0)