Spread vs slice luna

JavaScript performance comparison

Test case created by vladimir-tikhonov

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [];
  for ( var i = 0; i < 1000000; ++i ) {
  	a.push(i);
  }
  window.gcx = []

};

Benchmark.prototype.teardown = function() {
  window.gcx = []

};
</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
slice
window.gcx = a.slice();
pending…
spread
window.gcx = [...a];
pending…
concat
window.gcx = a.concat();
pending…
foropt
const l = a.length;
const x = new Array(l);
for ( let i = 0; i < l; i++ ) {
x[i] = a[i];
}

window.gcx = x;
pending…
for
const x = [];
for ( let i = 0; i < a.length; i++ ) {
x.push(a[i]);
}

window.gcx = x;
pending…

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

0 Comments