Zero fill matrix

Benchmark created on


Description

fill matrix with zeros

Setup

function makeZeroMatrix(width, height) {
    let matrix = [];
    for (let x = 0; x < height; x++) {
        matrix[x] = [];
        for (let y = 0; y < width; y++) {
            matrix[x][y] = 0;
        }
    }
    return matrix;
}

function makeZeroMatrixAlloc(width, height) {
    let matrix = new Array(height);
    for (let x = 0; x < height; x++) {
        matrix[x] = new Array(width);
        for (let y = 0; y < width; y++) {
            matrix[x][y] = 0;
        }
    }
    return matrix;
}

function makeZeroMatrixFunc(width, height) {
    return new Array(height).fill(0).map(_row => new Array(width).fill(0));
}

Test runner

Ready to run.

Testing in
TestOps/sec
Simple
makeZeroMatrix(8,8);
ready
Preallocated Arrays
makeZeroMatrixAlloc(8,8);
ready
Fill and Map
makeZeroMatrixFunc(8,8)
ready

Revisions

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