-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(benchpress): add benchpress config and flatmap spec
- Loading branch information
1 parent
fa06dd5
commit 0441dea
Showing
4 changed files
with
145 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}; |