Push vs Immutable

JavaScript performance comparison

Test case created by TonyJ

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var list = [];
  var toPush = (new Array(1000)).fill(0).map((e, i) => i);

};

Benchmark.prototype.teardown = function() {
  console.log(list.length);
  list = []

};
</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
push
toPush.map(n => list.push(n));
pending…
immutable-spread
list = toPush.reduce((all, n) => [...all, n], []);
pending…
immutable-concat
list = toPush.reduce((all, n) => all.concat([n]), []);
pending…

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

0 Comments