Skip to content

Commit

Permalink
perf(pluck,bufferTime,asObservable): add performance tests for pluck(…
Browse files Browse the repository at this point in the history
…), bufferTime() and asObservable() operators (#2491)

* perf(pluck,asobservable): add performance tests for pluck and asObservable operators

* perf(bufferTime): add performance test for bufferTime operator
  • Loading branch information
martinsik authored and benlesh committed Mar 30, 2018
1 parent 9fea36d commit 24506b3
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
24 changes: 24 additions & 0 deletions perf/micro/current-thread-scheduler/operators/asobservable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var oldRangeWithImmediateScheduler = RxOld.Observable.range(0, 250, RxOld.Scheduler.currentThread);
var newRangeWithImmediateScheduler = RxNew.Observable.range(0, 250, RxNew.Scheduler.queue);

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old asObservable() with immediate scheduler', function () {
var oldSubject = new RxOld.Subject();

oldSubject.asObservable().subscribe(_next, _error, _complete);
oldRangeWithImmediateScheduler.subscribe(oldSubject);
})
.add('new asObservable() with immediate scheduler', function () {
var newSubject = new RxNew.Subject();

newSubject.asObservable().subscribe(_next, _error, _complete);
newRangeWithImmediateScheduler.subscribe(newSubject);
});
};
23 changes: 23 additions & 0 deletions perf/micro/current-thread-scheduler/operators/pluck-nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var source = [];
for (var i = 0; i < 25; i++) {
source.push({'a': {'b': {'c': i }}});
}

var oldPluckWithImmediateScheduler = RxOld.Observable.from(source, null, null, RxOld.Scheduler.currentThread).pluck('a', 'b', 'c');
var newPluckWithImmediateScheduler = RxNew.Observable.from(source, RxNew.Scheduler.queue).pluck('a', 'b', 'c');

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old pluck() with nested properties and current thread scheduler', function () {
oldPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new pluck() with nested properties and current thread scheduler', function () {
newPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};
23 changes: 23 additions & 0 deletions perf/micro/current-thread-scheduler/operators/pluck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var source = [];
for (var i = 0; i < 25; i++) {
source.push({'p': i});
}

var oldPluckWithImmediateScheduler = RxOld.Observable.from(source, null, null, RxOld.Scheduler.currentThread).pluck('p');
var newPluckWithImmediateScheduler = RxNew.Observable.from(source, RxNew.Scheduler.queue).pluck('p');

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old pluck() with current thread scheduler', function () {
oldPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new pluck() with current thread scheduler', function () {
newPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};
24 changes: 24 additions & 0 deletions perf/micro/immediate-scheduler/operators/asobservable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var oldRangeWithImmediateScheduler = RxOld.Observable.range(0, 250, RxOld.Scheduler.immediate);
var newRangeWithImmediateScheduler = RxNew.Observable.range(0, 250);

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old asObservable() with immediate scheduler', function () {
var oldSubject = new RxOld.Subject();

oldSubject.asObservable().subscribe(_next, _error, _complete);
oldRangeWithImmediateScheduler.subscribe(oldSubject);
})
.add('new asObservable() with immediate scheduler', function () {
var newSubject = new RxNew.Subject();

newSubject.asObservable().subscribe(_next, _error, _complete);
newRangeWithImmediateScheduler.subscribe(newSubject);
});
};
18 changes: 18 additions & 0 deletions perf/micro/immediate-scheduler/operators/buffertime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var oldBufferWithImmediateScheduler = RxOld.Observable.interval(25, RxOld.Scheduler.immediate).bufferWithTime(60, RxOld.Scheduler.immediate).take(3);
var newBufferWithImmediateScheduler = RxNew.Observable.interval(25).bufferTime(60).take(3);

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old bufferTime() with immediate scheduler', function () {
oldBufferWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new bufferTime() with immediate scheduler', function () {
newBufferWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};
23 changes: 23 additions & 0 deletions perf/micro/immediate-scheduler/operators/pluck-nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var source = [];
for (var i = 0; i < 25; i++) {
source.push({'a': {'b': {'c': i }}});
}

var oldPluckWithImmediateScheduler = RxOld.Observable.from(source, null, null, RxOld.Scheduler.immediate).pluck('a', 'b', 'c');
var newPluckWithImmediateScheduler = RxNew.Observable.from(source).pluck('a', 'b', 'c');

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old pluck() with nested properties and immediate scheduler', function () {
oldPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new pluck() with nested properties and immediate scheduler', function () {
newPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};
23 changes: 23 additions & 0 deletions perf/micro/immediate-scheduler/operators/pluck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var RxOld = require('rx');
var RxNew = require('../../../../index');

module.exports = function (suite) {
var source = [];
for (var i = 0; i < 25; i++) {
source.push({'p': i});
}

var oldPluckWithImmediateScheduler = RxOld.Observable.from(source, null, null, RxOld.Scheduler.immediate).pluck('p');
var newPluckWithImmediateScheduler = RxNew.Observable.from(source).pluck('p');

function _next(x) { }
function _error(e) { }
function _complete() { }
return suite
.add('old pluck() with immediate scheduler', function () {
oldPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
})
.add('new pluck() with immediate scheduler', function () {
newPluckWithImmediateScheduler.subscribe(_next, _error, _complete);
});
};

0 comments on commit 24506b3

Please sign in to comment.