Dot Notation Parse Test

JavaScript performance comparison

Test case created by Jay Baugh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var item = {
      'a': {
        'b': {
          'c': ['hello']
        }
      }
    };
   
    function dotParser(obj, dotPath) {
   
      var path = dotPath.split(".");
      var result = obj;
      var i;
      for (i = 0; i < path.length; i++) {
        result = result[path[i]];
        if (result === undefined) {
          result = undefined;
          break;
        }
      }
      return (result);
    }
   
    function index(obj,i) { return obj[i]; }
    function dotParser2(obj, dotPath) {
      return(dotPath.split('.').reduce(index, obj));
    }
   
};
</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
Eval
var result = eval("item.a.b.c")[0];
pending…
Parse
var result = dotParser(item, "a.b.c")[0];
pending…
Reduce
var result = dotParser2(item, "a.b.c")[0];
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment