NoHoleArray

JavaScript performance comparison

Test case created by SanderElias

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var n     = 10000000;
  var value = 0;

};
</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
pre-sized array
function newFilledArray(len, val) {
    const rv = new Array(len);
    for (let i = 0; i < len; i++) {
        rv[i] = val;
    }
    return rv;
}
newFilledArray(n, value);
pending…
Push
function newArray(size, val) {
  const list = [];
  for (let i = 0; i < size; i++) {
    list.push(val);
  }
  return list;
}
newArray(n,value)
pending…
unsized array
function makeArrayOf(value, length) {
  const arr = [];
  for (let i = 0; i < length; i++) {
    arr[i] = value;
  }
  return arr;
}

makeArrayOf(value, n);
pending…
sander Array.from
function newArray1(size,defaultVal) {
  return Array.from({length:size}, () => defaultVal)
}
newArray1(n,value)
pending…
sander Array.fill
function filledArray(size,val) {
  return new Array(size).fill(val)
}
filledArray(n,value)
pending…

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

Compare results of other browsers

0 Comments