Deep Clone lodash JSON

Benchmark created by Adam on


Description

Comparing performance of lodash's deep clone to stringifying JSON and then decoding that again.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script>
var data = {};

for (var x = 0; x < 1000; x++) {
  data[x] = {};

  for (var y = 0; y < 5; y++) {
    data[x][y] = [x + y];
  }
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
JSON Stringify Clone
JSON.parse(JSON.stringify(data));
ready
lodash Deep Clone
_.cloneDeep(data);
ready
jQuery Clone
jQuery.extend(true, {}, data);
ready

Revisions

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