fasdghkfagkfjgksdgfkjasdgkf

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function doSomething() {};
    var getProperty = function(context, selector, dummy) {
      if (typeof selector !== "string")
        return;
   
      var re = /(\[\d*\])/ig,
        parts = selector.split("."),
        i,
        propVal = context,
        part;
   
      if (dummy)
        doSomething();
   
      for (i = 0; i < parts.length; i++) {
        if (!propVal)
          return undefined;
        part = parts[i];
        if (part === "")
          return;
        if (part.indexOf('[') >= 0) {
          var arrName = part.substr(0, part.indexOf('['));
          var found = part.match(re);
          propVal = propVal[arrName] !== undefined ? propVal[arrName] : propVal['@' + arrName];
          for (var f = 0, flen = found.length; f < flen; f++) {
            if (!propVal)
              return undefined;
            var index = found[f].substr(1, found[f].length - 2);
            propVal = propVal[index];
          }
        } else
          propVal = propVal[part] !== undefined ? propVal[part] : propVal['@' + part];
      }
      return propVal;
    }
   
    var o = {
      a: {
        b: {
          c: {
            d: {
              e: 10
            }
          }
        }
      }
    }, r;
};
</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
simple
r = o && o.a && o.a.b && o.a.b.c && o.a.b.c.d && o.a.b.c.d.e;
pending…
cached
var t = o;
r = t && (t = o.a) && (t = t.b) && (t = t.c) && (t = t.d) && t.e;
pending…
complex
r = getProperty(o, 'a.b.c.d.e')
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