For Loop Comparisons

JavaScript performance comparison

Test case created by Andrew Klatzke

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var x = {};
    var keys = [];
    for( var i = 0; i < 1000; i++){ x["a" + i] = i; }
    keys = Object.keys(x);
};
</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
For In
for( var y in keys ){
  var z = x[y];
}
pending…
y=0,n;
for( var y = 0, z; z = x[keys[i]]; y++ ){

}
pending…
for i = 0;
for( var y = 0; y < keys.length; y++){
 var z = x[keys[y]]
}
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