jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Cost of Angular's $watchCollection vs $watch
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script>
<script>
var app = angular.module('app', []);
var deregs = [];
app.service('Watch', function($rootScope) {
return {
run: function() {
deregs.push($rootScope.$watch('data', function(n, o) {
if(n[0].obj.obj.boolean === true){
console.log('yes im the truth');
} else {
console.log('boo im false');
}
},true));
$rootScope.$digest();
}
};
});
app.service('WatchCollection', function($rootScope) {
return {
run: function() {
deregs.push($rootScope.$watchCollection('data', function(n, o) {
if(n[0].obj.obj.boolean === true){
console.log('yes im the truth 2');
} else {
console.log('boo im false');
}
}));
$rootScope.$digest();
}
};
});
</script>
<div id="myApp" ng-app="app"></div>
var i = angular.element(document.getElementById('myApp')).injector();
var scope = i.get('$rootScope');
scope.data = [
{'bob': true, 'obj': {'obj': {'bool': false}}}, {'frank': false}, {'jerry': 'hey'}, {'bargle': false},
{'bob': true}, {'bob': true}, {'frank': false}, {'jerry': 'hey'}, {'bargle': false},{'bob': true},{'bob': true}, {'frank': false}];
angular.forEach(deregs, function(d) {
d();
});
Ready to run.
Test | Ops/sec | |
---|---|---|
$watch |
| ready |
$watchCollection |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.