Extend function comparisons

JavaScript performance comparison

Test case created by John Cockrell

Info

Comparing jQuery and Underscore extend() functions for performance.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var targetObject,
        extendingObject,
        targetArray = [],
        extendingArray = [];
   
   
    //  Populate Arrays.
    for (var i = 0; i < 10000; i += 1) {
        targetArray[i] = i;
        extendingArray[i] = (i * 12) / 3;
    }
   
    targetObject = {
            a: [],
            b: {
                one: "one",
                two: {
                  point1: 2.1,
                  point2: 2.2,
                  point3: 2.3
                },
                three: [3.1, 3.2, 3.3, 3.4]
            },
            c: function(b) { b = 1; return b },
            d: "okay",
            e: 1
        };
   
    extendingObject = {
       prop: function(){ return "prop"; },
       d: targetArray,
       f: function getE() { this.e = this.e * 1000; return this.e; }
    };
};
</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
jQuery.extend()
$.extend(targetObject, extendingObject);
$.extend(targetArray, extendingArray);
$.extend(targetObject, targetArray, extendingArray);
pending…
Underscore.extend()
_.extend(targetObject, extendingObject);
_.extend(targetArray, extendingArray);
_.extend(targetObject, targetArray, extendingArray);
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