Object.keys and for in

JavaScript performance comparison

Test case created by Aakash Kharche

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var obj = {
    a: 1,
    b: 2,
    c: 3,
    d: 4,
    e: 5,
    f: 6,
    g: 7,
    h: 8, 
    i: 9
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
object.keys
Object.keys(obj).forEach(function(key) { 
 console.log(key);
});
pending…
for in
for(var key in obj) {
 console.log(key);
}
pending…

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

0 Comments