Object Keys Vs For In

JavaScript performance comparison

Test case created by Danny

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var jsonObj = {
    prop1: "abc",
    prop2: "def",
    prop3: "ghi"
    prop4: "jkl"
    prop5: "mno"
    prop6: "pqr"
    prop7: "stu"
    prop8: "vwx"
    prop9: "yz"
  }

};
</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
var result = "";
Object.keys(jsonObj).forEach(function(key) {
  result = result + jsonObj[key];
});
pending…
For In
var result = "";
for (key in jsonObj) {
  if (jsonObj.hasOwnProperty(key)) {
    result = result + jsonObj[key];
  }
}
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.

0 Comments