array-copy (v4)

Revision 4 of this benchmark created by Felipe N. Moura on


Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
slicing
b = a.slice(0);
ready
join and split
b = a.join('@@@').split('@@@');
ready
forEach
b = [];
a.forEach(function(cur) {
  b.push(cur);
});
ready
for in
b = [];
for (var cur in a) {
  b.push(a[cur]);
}
ready
concat
b = a.concat();
ready
for in initializing array
b = new Array(a.length);
for (var cur in a) {
  b.push(a[cur]);
}
ready
map
b = a.map(function(x) {
  return x;
});
ready
filtering
alwaysTrue = function() {
  return true;
}
b = a.filter(alwaysTrue);
ready
verbose for
b = new Array(a.length);
var len = a.length;
for (var i = 0; i < len; i++) {
  b[i] = a[i];
}
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