Object.keys with inheritance

JavaScript performance comparison

Test case created by Mike Baynton

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function BaseClass() {}
  for (var i = 0; i < 100; i++) {
    BaseClass.prototype["p" + i] = i;
  }
  
  function SubClass() {}
  SubClass.prototype = BaseClass.prototype;
  
  var objInTest = new SubClass();
  
  
  function polyfillKeys(obj) {
    var output = [];
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        output.push(key);
      }
    }
    return output;
  }
  // could do Object.keys = polyfillKeys

};
</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
Native Object.keys
var keys = Object.keys(objInTest);
pending…
ES3 polyfill Object.keys
var keys = polyfillKeys(objInTest);
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