From 8359af9865500307a0972a1efcedcd0aacf9372b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gabriel=20Lima?= Date: Thu, 4 Feb 2016 13:49:05 -0300 Subject: [PATCH] chore(micro-perf): add perf tests for switchMapTo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Results on a Intel Core i7-3770 (Ivy Bridge) running Ubuntu: | RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved -------------------------------------------------------------------------------------------------- switchmapto-resultselector - immediate | 1,695 (±1.02%) | 12,229 (±1.15%) | 7.21x | 621.3% switchmapto - immediate | 2,910 (±0.80%) | 32,560 (±0.99%) | 11.19x | 1,018.8% switchmapto-resultselector | 2,621 (±0.87%) | 12,473 (±0.49%) | 4.76x | 375.9% switchmapto | 3,300 (±2.11%) | 15,433 (±0.57%) | 4.68x | 367.7% --- .../operators/switchmapto-resultselector.js | 21 +++++++++++++++++++ .../operators/switchmapto.js | 20 ++++++++++++++++++ .../operators/switchmapto-resultselector.js | 21 +++++++++++++++++++ .../operators/switchmapto.js | 20 ++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 perf/micro/current-thread-scheduler/operators/switchmapto-resultselector.js create mode 100644 perf/micro/current-thread-scheduler/operators/switchmapto.js create mode 100644 perf/micro/immediate-scheduler/operators/switchmapto-resultselector.js create mode 100644 perf/micro/immediate-scheduler/operators/switchmapto.js diff --git a/perf/micro/current-thread-scheduler/operators/switchmapto-resultselector.js b/perf/micro/current-thread-scheduler/operators/switchmapto-resultselector.js new file mode 100644 index 0000000000..9a117ce204 --- /dev/null +++ b/perf/micro/current-thread-scheduler/operators/switchmapto-resultselector.js @@ -0,0 +1,21 @@ +var RxOld = require('rx'); +var RxNew = require('../../../../index'); + +module.exports = function (suite) { + var resultSelector = function (x, y, ix, iy) { return x + y + ix + iy; }; + var oldSwitchMapToWithCurrentThreadScheduler = RxOld.Observable.range(0, 25, RxOld.Scheduler.currentThread) + .flatMapLatest(RxOld.Observable.range(0, 10, RxOld.Scheduler.currentThread), resultSelector); + var newSwitchMapToWithCurrentThreadScheduler = RxNew.Observable.range(0, 25, RxNew.Scheduler.queue) + .switchMapTo(RxNew.Observable.range(0, 10, RxNew.Scheduler.queue), resultSelector); + + function _next(x) { } + function _error(e) { } + function _complete() { } + return suite + .add('old switchMapTo with resultSelector and current thread scheduler', function () { + oldSwitchMapToWithCurrentThreadScheduler.subscribe(_next, _error, _complete); + }) + .add('new switchMapTo with resultSelector and current thread scheduler', function () { + newSwitchMapToWithCurrentThreadScheduler.subscribe(_next, _error, _complete); + }); +}; diff --git a/perf/micro/current-thread-scheduler/operators/switchmapto.js b/perf/micro/current-thread-scheduler/operators/switchmapto.js new file mode 100644 index 0000000000..1684c3abf8 --- /dev/null +++ b/perf/micro/current-thread-scheduler/operators/switchmapto.js @@ -0,0 +1,20 @@ +var RxOld = require('rx'); +var RxNew = require('../../../../index'); + +module.exports = function (suite) { + var oldSwitchMapToWithCurrentThreadScheduler = RxOld.Observable.range(0, 25, RxOld.Scheduler.currentThread) + .flatMapLatest(RxOld.Observable.range(0, 10, RxOld.Scheduler.currentThread)); + var newSwitchMapToWithCurrentThreadScheduler = RxNew.Observable.range(0, 25, RxNew.Scheduler.queue) + .switchMapTo(RxNew.Observable.range(0, 10, RxNew.Scheduler.queue)); + + function _next(x) { } + function _error(e) { } + function _complete() { } + return suite + .add('old switchMapTo with current thread scheduler', function () { + oldSwitchMapToWithCurrentThreadScheduler.subscribe(_next, _error, _complete); + }) + .add('new switchMapTo with current thread scheduler', function () { + newSwitchMapToWithCurrentThreadScheduler.subscribe(_next, _error, _complete); + }); +}; diff --git a/perf/micro/immediate-scheduler/operators/switchmapto-resultselector.js b/perf/micro/immediate-scheduler/operators/switchmapto-resultselector.js new file mode 100644 index 0000000000..27b399559e --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/switchmapto-resultselector.js @@ -0,0 +1,21 @@ +var RxOld = require('rx'); +var RxNew = require('../../../../index'); + +module.exports = function (suite) { + var resultSelector = function (x, y, ix, iy) { return x + y + ix + iy; }; + var oldSwitchMapToWithImmediateScheduler = RxOld.Observable.range(0, 25, RxOld.Scheduler.immediate) + .flatMapLatest(RxOld.Observable.range(0, 10, RxOld.Scheduler.immediate), resultSelector); + var newSwitchMapToWithImmediateScheduler = RxNew.Observable.range(0, 25) + .switchMapTo(RxNew.Observable.range(0, 10), resultSelector); + + function _next(x) { } + function _error(e) { } + function _complete() { } + return suite + .add('old switchMapTo with resultSelector and immediate scheduler', function () { + oldSwitchMapToWithImmediateScheduler.subscribe(_next, _error, _complete); + }) + .add('new switchMapTo with resultSelector and immediate scheduler', function () { + newSwitchMapToWithImmediateScheduler.subscribe(_next, _error, _complete); + }); +}; diff --git a/perf/micro/immediate-scheduler/operators/switchmapto.js b/perf/micro/immediate-scheduler/operators/switchmapto.js new file mode 100644 index 0000000000..a4f0b6c3bc --- /dev/null +++ b/perf/micro/immediate-scheduler/operators/switchmapto.js @@ -0,0 +1,20 @@ +var RxOld = require('rx'); +var RxNew = require('../../../../index'); + +module.exports = function (suite) { + var oldSwitchMapToWithImmediateScheduler = RxOld.Observable.range(0, 25, RxOld.Scheduler.immediate) + .flatMapLatest(RxOld.Observable.range(0, 10, RxOld.Scheduler.immediate)); + var newSwitchMapToWithImmediateScheduler = RxNew.Observable.range(0, 25) + .switchMapTo(RxNew.Observable.range(0, 10)); + + function _next(x) { } + function _error(e) { } + function _complete() { } + return suite + .add('old switchMapTo with immediate scheduler', function () { + oldSwitchMapToWithImmediateScheduler.subscribe(_next, _error, _complete); + }) + .add('new switchMapTo with immediate scheduler', function () { + newSwitchMapToWithImmediateScheduler.subscribe(_next, _error, _complete); + }); +};