String vs. Integer Object Indices

JavaScript performance comparison

Test case created by Gavin Kistner

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var $ints = [],
        $strs = [],
        $ostr = {};
    for (var i=0,len=Math.pow(2,15);i<len;++i){
      $ints.push(i);
      $strs.push(i+"");
      $ostr[i+""] = i;
    }
};
</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
Get Integer
for (var x,i=$ints.length;i--;) x=$ostr[$ints[i]];
pending…
Get String
for (var x,i=$ints.length;i--;) x=$ostr[$strs[i]];
pending…
Set Integer
for (var o={},i=$ints.length;i--;) o[$ints[i]] = $ints[i];
pending…
Set String
for (var o={},i=$ints.length;i--;) o[$strs[i]] = $ints[i];
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