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
Testing $parse versus a javascript function to extract nested object using a string key. http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
<script>
function ParseCtrl ($scope, $parse) {
var data={
depth: 1,
nested: {
depth: 2,
nested: {
depth: 3
}
}
};
$scope.parseData = function(i){
$parse('depth');
$parse('nested.depth');
$parse('nested.nested.depth');
}
$scope.refData = function(){
ref(data, 'depth');
ref(data, 'nested.depth');
ref(data, 'nested.nested.depth');
}
$scope.defensiveChecks = function(){
data != null &&
data.depth != null ?
data.depth :
undefined;
data != null &&
data.nested != null &&
data.nested.depth != null ?
data.nested.depth :
undefined;
data != null &&
data.nested != null &&
data.nested.depth != null &&
data.nested.nested.depth != null ?
data.nested.nested.depth :
undefined;
}
function ref(obj, path, def){
if (!path) return path;
for(var i = 0, path = path.split('.'),len = path.length; i < len; i++){
if(!obj || typeof obj !== 'object') return def;
obj = obj[path[i]];
}
if(obj === undefined) return def;
return obj;
}
};
angular.element(document).ready(function() {
window.ANGAPP = {
scope: $('#angular').scope()
};
});
</script>
<div style="width: 200px; height: 300px; overflow: hidden" ng-app>
<span ng-controller="ParseCtrl" id="angular"></span>
</div>
Ready to run.
Test | Ops/sec | |
---|---|---|
Parse |
| ready |
Ref |
| ready |
Defensive |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.