object clone jquery vs underscore vs lodash

Benchmark created by Simon Gong on


Preparation HTML

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>

Setup

var deepObject = {
      a: {
        b: {
          c: 6
        },
        d: 8
      },
      e: "hello",
      p: 9,
      q: 10,
      r: true,
      s: new Date(),
      t: function () {
        var foo = 'bar';
        return foo;
      },
      v: [1, 2, 3],
      __proto__: {
        constructor: function(){},
        __proto__: {}
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Deep Clone
$.extend(true, {}, deepObject);
ready
Underscore
_.clone(deepObject)
ready
Lo-dash
lodash.cloneDeep(deepObject)
ready
JSON
JSON.parse(JSON.stringify(deepObject));
ready

Revisions

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