jQuery $.extend vs. JSON.parse

JavaScript performance comparison

Revision 6 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var o = {};
   
    var i = 10;
   
    var k, v;
   
    var d = ["", true, false, 0, Array(i), {}];
   
    var l = d.length;
   
    var r;
   
    while (i--) {
        k = btoa(Math.random() * Date.now());
        v = d[Math.floor(Math.random() * l)];
        o[k] = v;
    }
   
    var s = JSON.stringify(o);
   
};
</script>

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
jQuery.extend({}, o);
pending…
JSON.parse
var j = JSON.stringify(s);
JSON.parse(j);
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