array cloning (v11)

Revision 11 of this benchmark created by Anton Kudris on


Description

speed comparissons between slice, splice, for, $.clone

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var a = ['z','a','q','w','s','x','c','d','v','e','f','t','r','g','t','m','y','h','t','y','j','i','o','l','f','s','d','j','n','m','c','u','i','e','w','h','r',',','w','e','n','r','w','n','e','b','f','2','3','4','2','3','4','n','j','m','f','d','s','j','d','y','f','g','2','3','h','f','s','j','d','b','m','f','h','s','d','h','f','o','2','3','i','z','a','q','w','s','x','c','d','v','e','f','t','r','g','t','m','y','h','t','y','j','i','o','l','f','s','d','j','n','m','c','u','i','e','w','h','r',',','w','e','n','r','w','n','e','b','f','2','3','4','2','3','4','n','j','m','f','d','s','j','d','y','f','g','2','3','h','f','s','j','d','b','m','f','h','s','d','h','f','o','2','3','i','z','a','q','w','s','x','c','d','v','e','f','t','r','g','t','m','y','h','t','y','j','i','o','l','f','s','d','j','n','m','c','u','i','e','w','h','r',',','w','e','n','r','w','n','e','b','f','2','3','4','2','3','4','n','j','m','f','d','s','j','d','y','f','g','2','3','h','f','s','j','d','b','m','f','h','s','d','h','f','o','2','3','i'];
</script>

Setup

var b = [];

Test runner

Ready to run.

Testing in
TestOps/sec
Slice
b = a.slice(0, a.length);
ready
concat
b = [].concat(a);
ready
Splice
b = a.splice(0, a.length);
ready
For
b = [];
for (var i = a.length-1; i >= 0; i--) {
    b.unshift(a[i]);
}
ready
bad for
b = [];
for (var i = 0; i < a.length; i++) {
    b.push(a[i]);
}
ready

Revisions

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