array-copy

JavaScript performance comparison

Revision 7 of this test case created by Felipe N Moura

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  a = [];
  for (var i = 0; i < 10000; i++) {
    a.push(i);
  }
  b = null;

};

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

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
slicing
b = a.slice(0);
pending…
join and split
b = a.join('@@@').split('@@@');
pending…
forEach
b = [];
a.forEach(function(cur) {
  b.push(cur);
});
pending…
for in
b = [];
for (var cur in a) {
  b.push(a[cur]);
}
pending…
concat
b = a.concat();
pending…
for verbose
b = new Array(a.length);
var len = a.length;
for (var i = 0; i < len; i++) {
  b[i] = a[i];
}
pending…
JSON
b = JSON.parse( JSON.stringify( a ) );
pending…

Compare results of other browsers

Revisions

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

0 Comments