Merge Objects vs jQuery .Externd()

JavaScript performance comparison

Test case created


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

Preparation code

<script src=""></script>
  var settings = { validate: false, limit: 5, name: "foo" };
  var options = { validate: true, name: "bar" };
  function merge_options(obj1,obj2){    var obj3 = {};    for (attrname in obj1) { obj3[attrname] = obj1[attrname]; }    for (attrname in obj2) { obj3[attrname] = obj2[attrname]; }    return obj3;}

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
merge_options(settings, options)
jQuery.extend(settings, options);

Compare results of other browsers


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:

1 comment

maven_peace commented :

Before you get tripped up by the results, you should take a look at jQuery's extend code. The call to jQuery's extend utilized in your example is actually overwriting the original settings object.

With this setup, your merge is not really a comparable operation. Switching to "jQuery.extend({},settings,options);" should be more accurate of a test.

Comment form temporarily disabled.

Add a comment