From 24506b3b78afe8d7721d100d828e84c9be9161cb Mon Sep 17 00:00:00 2001 From: Martin Sikora Date: Sat, 31 Mar 2018 00:40:16 +0200 Subject: [PATCH] perf(pluck,bufferTime,asObservable): add performance tests for pluck(), bufferTime() and asObservable() operators (#2491) * perf(pluck,asobservable): add performance tests for pluck and asObservable operators * perf(bufferTime): add performance test for bufferTime operator --- .../operators/asobservable.js | 24 +++++++++++++++++++ .../operators/pluck-nested.js | 23 ++++++++++++++++++ .../operators/pluck.js | 23 ++++++++++++++++++ .../operators/asobservable.js | 24 +++++++++++++++++++ .../operators/buffertime.js | 18 ++++++++++++++ .../operators/pluck-nested.js | 23 ++++++++++++++++++ .../immediate-scheduler/operators/pluck.js | 23 ++++++++++++++++++ 7 files changed, 158 insertions(+) create mode 100644 perf/micro/current-thread-scheduler/operators/asobservable.js create mode 100644 perf/micro/current-thread-scheduler/operators/pluck-nested.js create mode 100644 perf/micro/current-thread-scheduler/operators/pluck.js create mode 100644 perf/micro/immediate-scheduler/operators/asobservable.js create mode 100644 perf/micro/immediate-scheduler/operators/buffertime.js create mode 100644 perf/micro/immediate-scheduler/operators/pluck-nested.js create mode 100644 perf/micro/immediate-scheduler/operators/pluck.js diff --git a/perf/micro/current-thread-scheduler/operators/asobservable.js b/perf/micro/current-thread-scheduler/operators/asobservable.js new file mode 100644 index 0000000000..fca259d9f7 --- /dev/null +++ b/perf/micro/current-thread-scheduler/operators/asobservable.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/current-thread-scheduler/operators/pluck-nested.js b/perf/micro/current-thread-scheduler/operators/pluck-nested.js new file mode 100644 index 0000000000..bddfea0922 --- /dev/null +++ b/perf/micro/current-thread-scheduler/operators/pluck-nested.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/current-thread-scheduler/operators/pluck.js b/perf/micro/current-thread-scheduler/operators/pluck.js new file mode 100644 index 0000000000..12e1f28195 --- /dev/null +++ b/perf/micro/current-thread-scheduler/operators/pluck.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/immediate-scheduler/operators/asobservable.js b/perf/micro/immediate-scheduler/operators/asobservable.js new file mode 100644 index 0000000000..6943d4d61c --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/asobservable.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/immediate-scheduler/operators/buffertime.js b/perf/micro/immediate-scheduler/operators/buffertime.js new file mode 100644 index 0000000000..584cc58798 --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/buffertime.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/immediate-scheduler/operators/pluck-nested.js b/perf/micro/immediate-scheduler/operators/pluck-nested.js new file mode 100644 index 0000000000..c2cecea063 --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/pluck-nested.js @@ -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); + }); +}; \ No newline at end of file diff --git a/perf/micro/immediate-scheduler/operators/pluck.js b/perf/micro/immediate-scheduler/operators/pluck.js new file mode 100644 index 0000000000..f1cd2d76c9 --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/pluck.js @@ -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); + }); +}; \ No newline at end of file