Count object keys

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var object = {
      a: 42,
      b: 100,
      c: 23,
      d: 5234,
      e: 11,
      f: 89,
      g: 100
    };
};
</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
var _hasOwn = Object.prototype.hasOwnProperty,
    count = 0,
    key;

for (key in object) {
  if (_hasOwn.call(object, key)) {
    count += 1;
  }
}

return count;
pending…
Object.keys
return Object.keys(object).length;
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