checknested efficiency

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function checkNested(obj /*, level1, level2, ... levelN*/) {
      var args = Array.prototype.slice.call(arguments),
          obj = args.shift();
   
      for (var i = 0; i < args.length; i++) {
        if (!obj.hasOwnProperty(args[i])) {
          return false;
        }
        obj = obj[args[i]];
      }
      return true;
    }
    function checkNestedFast(obj /*, level1, level2, ... levelN*/) {
      for (var i = 1; i < arguments.length; i++) {
        if (!obj.hasOwnProperty(arguments[i])) {
          return false;
        }
        obj = obj[arguments[i]];
      }
      return true;
    }
   
    var test = {level1:{level2:{level3:'level3'}} };
   
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
original
checkNested(test, 'level1', 'level2', 'level3'); // true
checkNested(test, 'level1', 'level2', 'foo'); // false
pending…
fast
checkNestedFast(test, 'level1', 'level2', 'level3'); // true
checkNestedFast(test, 'level1', 'level2', 'foo'); // false
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment