2D matrix performance

Benchmark created by Angelito on


Test runner

Ready to run.

Testing in
TestOps/sec
matrix normal array
"use strict"
function performance(counter){
  const rows=1000
  const columns=1000
  const matrix=createMatrix(rows,columns)
  matrix[0][0]=counter
  for (let i = 0; i < rows-1; ++i) {
    for (let j = 0; j < columns; ++j) {
      matrix[i+1][j]=matrix[i][j]+(i+j)
    }
  }
  let res=0
  for (let j = 0; j < columns; ++j) {
    res=res+matrix[rows-1][j];
  }
  console.log(res)
}

function createMatrix(rows,columns){
  const matrix=new Array(rows)
  for (let i = 0; i < rows; i++){
    const arr=new Array(columns)
    arr.fill(0)
    matrix[i]=arr
  }
  return matrix
}

function main(){
  for (let r = 0; r < 100; r++) {
    performance(r*2)
  }
}

main()
ready
matrix typed array
"use strict"
function performance(counter){
  const rows=1000
  const columns=1000
  const matrix=createMatrix(rows,columns)
  matrix[0][0]=counter
  for (let i = 0; i < rows-1; ++i) {
    for (let j = 0; j < columns; ++j) {
      matrix[i+1][j]=matrix[i][j]+(i+j)
    }
  }
  let res=0
  for (let j = 0; j < columns; ++j) {
    res=res+matrix[rows-1][j];
  }
  console.log(res)
}

function createMatrix(rows,columns){
  const matrix=new Array(rows)
  for (let i = 0; i < rows; i++){
    const arr=new Uint32Array(columns)
    arr.fill(0)
    matrix[i]=arr
  }
  return matrix
}

function main(){
  for (let r = 0; r < 100; r++) {
    performance(r*2)
  }
}

main()
ready

Revisions

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

  • Revision 1: published by Angelito on