array-mutable-vs-inmutable

JavaScript performance comparison

Test case created by liyuanqiu

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const n = 10000;
  const defaultValue = 3;
  var arr = Array(n).fill(defaultValue);

};

Benchmark.prototype.teardown = function() {
  arr = Array(n).fill(defaultValue);

};
</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
mutable
for (let i = 0; i < n; i += 1) {
  arr[i] = arr[i] ** 2;
}
pending…
immutable
const nextArr = Array(n);
for (let i = 0; i < n; i += 1) {
  nextArr[i] = arr[i] ** 2;
}
pending…
immutable-functional
const nextArr = arr.map(item => item ** 2);
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