Merge Objects vs jQuery .Externd()

JavaScript performance comparison

Revision 3 of this test case created

Info

Testing speed of js merge object properties script vs using jquery's extend method

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var settings = { validate: false, limit: 5, name: "foo" };
  var options = { validate: true, name: "bar" };
  function merge_options(object1, object2){
    var merged = {},
        prop;
               
    for (prop in object1) { merged[prop] = object1[prop]; }
    for (prop in object2) { merged[prop] = object2[prop]; }
               
    return merged;
  }

function MergeRecursive(obj1, obj2) {

  for (var p in obj2) {
    try {
      // Property in destination object set; update its value.
      if ( obj2[p].constructor==Object ) {
        obj1[p] = MergeRecursive(obj1[p], obj2[p]);

      } else {
        obj1[p] = obj2[p];

      }

    } catch(e) {
      // Property in destination object not set; create it and set its value.
      obj1[p] = obj2[p];

    }
  }

  return obj1;
}
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
JavaScript
merge_options(settings, options)
pending…
jQuery
jQuery.extend({}, settings, options);
pending…
JavaScript recursive
MergeRecursive(settings, options)
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. Here’s a list of current revisions for this page:

0 comments

Add a comment