Skip to content

Commit

Permalink
feat(benchpress): add benchpress config and flatmap spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbcross committed May 26, 2015
1 parent fa06dd5 commit 0441dea
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 66 deletions.
33 changes: 33 additions & 0 deletions perf/flatMap/flatmap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var benchpress = require('benchpress');
var runner = new benchpress.Runner([
benchpress.SeleniumWebDriverAdapter.PROTRACTOR_BINDINGS,
benchpress.Validator.bindTo(benchpress.RegressionSlopeValidator),
benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE).toValue(10),
benchpress.bind(benchpress.RegressionSlopeValidator.METRIC).toValue('script'),
benchpress.bind(benchpress.Options.FORCE_GC).toValue(false)
]);

describe('flatMap comparison', function() {
it('should be fast in Rx3', function(done) {
browser.ignoreSynchronization = true;
browser.get('http://localhost:8080/perf/flatMap/index.html');
runner.sample({
id: 'flatMap Rx3',
execute: function() {
$('#rx-3-flatmap').click();
}
}).then(done, done.fail);
});


it('should be fast in Rx2', function (done) {
browser.ignoreSynchronization = true;
browser.get('http://localhost:8080/perf/flatMap/index.html');
runner.sample({
id: 'flatMap Rx2',
execute: function() {
$('#rx-2-flatmap').click();
}
}).then(done, done.fail);
});
});
7 changes: 5 additions & 2 deletions perf/flatMap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<head>
<meta charset="UTF-8">
<title>RxJS 3 Perf Tests</title>
<script src="../../dist/global/rx.js"></script>
<script src="../../node_modules/rx/dist/rx.all.js"></script>

<script src="../../assets/requirejs/require.js"></script>
<script src="perf.js"></script>
</head>
<body>
<a href="../">perf index</a>
<button id="rx-3-flatmap">Rx3 FlatMap Test</button>
<button id="rx-2-flatmap">Rx2 FlatMap Test</button>
<script src="perf.js"></script>
</body>
</html>
122 changes: 58 additions & 64 deletions perf/flatMap/perf.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,71 @@
var noop = function(){};

require({
baseUrl: '../../',
paths: {
'benchmark': '../../assets/benchmark/benchmark',
'platform': '../../assets/platform/platform',
'lodash': '../../assets/lodash',
'rx2': '../../assets/rxjs2/rx',
'perf-helpers': '../perf/perf-helpers'
var Rx3TestObservable = new Observable(function(generator) {
debugger
var i = 1000;
while (i--) {
generator.next(i);
}
},
['benchmark', 'src/observable/observable', 'src/subscription/subscription', 'rx2', 'perf-helpers'],
function(Benchmark, observable, Subscription, Rx, helpers) {
var Observable = observable.Observable;
var printLn = helpers.printLn;

printLn('starting tests');
var suite = new Benchmark.Suite;
generator.return();

//HACK: junk subscription
return new Subscription(noop);
});

var noop = function(){};

var Rx2TestObservable = Rx.Observable.create(function(observer) {
var i = 1000;
while (i--) {
observer.onNext(i);
}

var testObservable = new Observable(function(generator) {
generator.next(42);
generator.return();
observer.onCompleted();

//HACK: junk subscription
return new Subscription(noop);
});
//HACK: junk subscription
return new noop;
});

var projection = function(x) {
return new Observable(function(generator) {
var tid = setTimeout(function(){
generator.next(x + '!!!');
generator.return();
});
return new Subscription(function(){
clearTimeout(tid);
});
var projectionRx3 = function(x) {
debugger
return new Observable(function(generator) {
var tid = setTimeout(function(){
console.log('timeout');
generator.next(x + '!!!');
generator.return();
});
return new Subscription(function(){
clearTimeout(tid);
});
};
});
};

var rx2TestObservable = Rx.Observable.just(42);
var projectionRx2 = function(x) {
return Rx.Observable.create(function(observer) {
var tid = setTimeout(function(){
observer.onNext(x + '!!!');
observer.onCompleted();
}, 0);

suite.
add('Observable.flatMap', function(d) {
testObservable.flatMap(projection).observer({
next: noop,
error: noop,
return: noop
});
}).
add('RxJS 2 Observable.flatMap', function(d) {
rx2TestObservable.flatMap(function(x) {
return Observable.create(function(observer) {
var tid = setTimeout(function(){
observer.onNext(x + '!!!');
observer.onCompleted();
}, 0);
return function(){
clearTimeout(tid);
}
});
};

return function(){
clearTimeout(tid);
}
});
}).forEach(noop, noop, noop);
})
var rx3FlatMap = document.querySelector('#rx-3-flatmap');
var rx2FlatMap = document.querySelector('#rx-2-flatmap');
rx3FlatMap.addEventListener('click', function() {
debugger
console.log('rx3 clicked');
Rx3TestObservable.flatMap(projectionRx3).observer({
next: noop,
error: noop,
return: noop
});
});

suite.
on('cycle', function(event) {
printLn(String(event.target));
}).
on('complete', function() {
printLn('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run({ async: true });
});
rx2FlatMap.addEventListener('click', function() {
console.log('rx2 clicked');
Rx2TestObservable.flatMap(projectionRx2).
forEach(noop, noop, noop);
});
49 changes: 49 additions & 0 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var httpServer = require('http-server');

exports.config = {
directConnect: true,

capabilities: {
browserName: 'chrome',
chromeOptions: {
//Important for benchpress to get timeline data from the browser
'args': ['--js-flags=--expose-gc'],
'perfLoggingPrefs': {
'traceCategories': 'blink.console,disabled-by-default-devtools.timeline'
}
},
loggingPrefs: {
performance: 'ALL'
}
},

specs: ['perf/**/*.spec.js'],
framework: 'jasmine2',

beforeLaunch: function () {
httpServer.createServer({
showDir: false
}).listen('8080', 'localhost');
},

onPrepare: function() {
// open a new browser for every benchmark
var originalBrowser = browser;
var _tmpBrowser;
beforeEach(function() {
global.browser = originalBrowser.forkNewDriverInstance();
global.element = global.browser.element;
global.$ = global.browser.$;
global.$$ = global.browser.$$;
});
afterEach(function() {
global.browser.quit();
global.browser = originalBrowser;
});
},

jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
};

0 comments on commit 0441dea

Please sign in to comment.