array-copy (v9)

Revision 9 of this benchmark created on


Preparation HTML

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

Setup

a = [];
  for (var i = 0; i < 10000; i++) {
    a.push(i);
  }
  b = null;

Teardown



            for (var i = 0; i < 10000; i++) {
    if (b[i] != i) throw "erro";
  }
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
map
b = a.map(function(i){return i;});
ready
JSON
b = JSON.parse( JSON.stringify( a ) );
ready
jQuery
b = $.extend(true, [], a);
ready
for verbose
b = new Array(a.length);
var len = a.length;
for (var i = 0; i < len; i++) {
  b[i] = a[i];
}
ready
for in
b = [];
for (var cur in a) {
  b.push(a[cur]);
}
ready
concat
b = a.concat();
ready
join and split
b = a.join('@@@').split('@@@');
ready
forEach
b = [];
a.forEach(function(cur) {
  b.push(cur);
});
ready
slicing
b = a.slice(0);
ready

Revisions

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

  • Revision 1: published by Felipe N Moura on
  • Revision 2: published by Daniel Martins on
  • Revision 3: published by Eduardo Bohrer on
  • Revision 4: published by Felipe N. Moura on
  • Revision 5: published on
  • Revision 6: published by massic80 on
  • Revision 7: published by Felipe N Moura on
  • Revision 8: published on
  • Revision 9: published on