JSON.stringify/parse vs. angular.copy array only (v5)

Revision 5 of this benchmark created on


Description

Though both methods are different in what they do, the result for "simple objects" (eg. without functions) is the same. A comparison of their speed might be useful.

Array only copy, just just objects.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>

Setup

window.testData = [];
    
    for (var i = 0; i < 10; i++)
      window.testData.push([1, 2, 3, 'a', 'b', 'c', 4, 5, 6]);

Test runner

Ready to run.

Testing in
TestOps/sec
Stringify object, then parse array
var data = JSON.parse(JSON.stringify(window.testData));
ready
Copy object with AngularJS array
var data = angular.copy(window.testData);
ready

Revisions

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