Spread operator-head-vs-tail

JavaScript performance comparison

Test case created by panzerdp

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const numbers1 = Array.from(Array(1000), (_, i) => i + 1);
  const numbers2 = Array.from(Array(10000), (_, i) => i + 1);

};
</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
[...array, item]
function appendToTail(item, array) {
  return [...array, item];
}

appendToTail(1, numbers1);
appendToTail(1, numbers2);
pending…
[item, ...array]
function appendToHead(item, array) {
  return [item, ...array];
}

appendToHead(1, numbers1);
appendToHead(1, numbers2);
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