in operator or array

JavaScript performance comparison

Test case created

Info

Perf check for in operator over object or array.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj ={};
    for(var i=0;i<200;i++) {
       obj[i.toString()]= i.toString() + "~~~~~~~~";
    }
};
</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
keys array
var keys = Object.keys(obj);

for(var i=keys.length;i>0;i--) {
 var prop = obj[keys[i-1]];
}
pending…
in operator
for(var i in obj) {
  var prop = obj[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