ES3 vs ES5 Mixins (v2)

Revision 2 of this benchmark created on


Description

Test the performance of traditional (ES3-style) mixin functions with mixin functions that handle ES5 properties, as proposed for Object.mixin in ES6.

Setup

var source = {
      a: 1,
      b: true,
      c: "test"
    };
    var target = {};

Test runner

Ready to run.

Testing in
TestOps/sec
ES3 all properties
for (var prop in source) {
  target[prop] = source[prop];
}
ready
ES3 own properties
for (var prop in source) {
  if (source.hasOwnProperty(prop)) {
    target[prop] = source[prop];
  }
}
ready
ES5 enumerable properties
Object.keys(source).forEach(function(key) {
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
ready
ES5 own properties
Object.getOwnPropertyNames(source).forEach(function(key) {
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
ready
ES5 enumerable properties (array)
var keys = Object.keys(source);
for (var i = 0, len = keys.length; i < len; ++i) {
  var key = keys[i];
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
}
ready
ES5 enumerable properties (array) with check
var keys = Object.keys(source);
for (var i = 0, len = keys.length; i < len; ++i) {
  var key = keys[i];
  if (key in target) {
    target[key] = source[key];
  }
  else {
    Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  }
}
ready

Revisions

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