Skip to content

Commit

Permalink
chore(test): add macro performance tests for zip
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Sep 3, 2015
1 parent e0d27ba commit 4e79536
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
24 changes: 24 additions & 0 deletions perf/macro/zip/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RxJS 3 Perf Tests</title>
<script src="../../../dist/global/Rx.js"></script>
<script type="text/javascript">
window.RxNext = window.Rx;
window.Rx = void 0;
</script>
<script src="../../../node_modules/rx/dist/rx.all.js"></script>

</head>
<body>
<a href="../">perf index</a>
<label>
Number of Iterations
<input type="number" name="iteration">
</label>
<button id="rx-2-zip">Rx2 Zip Test</button>
<button id="rx-3-zip">RxNext Zip Test</button>
<script src="perf.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions perf/macro/zip/perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var iterationInput = document.querySelector('input[name=iteration]');
var match = /iterations=(\w+)/.exec(decodeURIComponent(location.search));

if (match) {
iterationInput.value = match[1];
}

var numIterations = iterationInput.valueAsNumber || 1000;

var Rx2Zip = document.querySelector('#rx-2-zip');
var RxNextZip = document.querySelector('#rx-3-zip');

var Rx2TestObservable = Rx.Observable.create(generator);
var RxNextTestObservable = new RxNext.Observable(generator);

var Rx2TestArgObservable = Rx.Observable.create(generator);
var RxNextTestArgObservable = new RxNext.Observable(generator);

Rx2Zip.addEventListener('click', function() {
Rx2TestObservable.zip(Rx2TestArgObservable).subscribe();
});

RxNextZip.addEventListener('click', function() {
RxNextTestObservable.zip(RxNextTestArgObservable).subscribe();
});

function generator(observer) {
var index = -1;
while(++index < numIterations) {
observer.onNext(index);
}
observer.onCompleted();
}
47 changes: 47 additions & 0 deletions perf/macro/zip/zip.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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(20),
benchpress.bind(benchpress.RegressionSlopeValidator.METRIC).toValue('scriptTime'),
benchpress.bind(benchpress.Options.FORCE_GC).toValue(false)
]);

describe('zip comparison', function () {
[
1000,
10000
].forEach(function (val) {
it('should be fast in Rx2', function (done) {
browser.ignoreSynchronization = true;
browser.get('http://localhost:8080/perf/macro/zip/index.html?iterations=' + val);
runner.sample({
id: 'zip Rx2',
execute: function () {
$('#rx-2-zip').click();
},
bindings: [
benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue({
iterations: val
})
]
}).then(done, done.fail);
});

it('should be fast in RxNext', function (done) {
browser.ignoreSynchronization = true;
browser.get('http://localhost:8080/perf/macro/zip/index.html?iterations=' + val);
runner.sample({
id: 'zip RxNext',
execute: function () {
$('#rx-3-zip').click();
},
bindings: [
benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue({
iterations: val
})
]
}).then(done, done.fail);
});
});
});

0 comments on commit 4e79536

Please sign in to comment.