Script Preparation code:
AخA
 
function gaussian(mean, variance) {
    return Math.sqrt(-2 * variance * Math.log(Math.random())) *
        Math.cos(2 * Math.PI * Math.random()) + mean;
}
Tests:
  • Algorithm 1

    x
     
    const n = 2;
    const columns = 4*n;
    const rows = 3*n;
    const cellWidth = 640/columns;
    const matrix = {};
    let population = rows*columns;
    const numParents = Math.ceil(0.2*rows*columns);
    for (let i = 0; i < rows; i++) {
        matrix[i] = {};
        for (let j = 0; j < columns; j++) {
          matrix[i][j] = 0;
        }
    }
    let p = 0;
    while (p < numParents) {
      try {
        for (let i = 0; i < rows; i++) {
          for (let j = 0; j < columns; j++) {
            if (p < numParents) {
              if (matrix[i][j] === 1) {
                continue;
              }
              if (Math.abs(gaussian(0,columns) > j)) {
                matrix[i][j] = 1;
                ++p;
              }
            } else {
              throw "";
            }
          }
        }
      } catch (e) {}
    }
  • Algorithm 2

     
    const n = 2;
    const columns = 4*n;
    const rows = 3*n;
    const cellWidth = 640/columns;
    const matrix = {};
    for (let i = 0; i < rows; i++) {
      matrix[i] = {}
      for (let j = 0; j < columns; j++) {
        matrix[i][j] = 0
      }
    }
    let population = rows*columns;
    let numParents = Math.ceil(0.2*rows*columns);
    for (let i = 0; i < numParents; i++) {
      let success = false;
      while (!success) {
        let columnIndex = null;
        while (columnIndex === null) {
          const rand = Math.floor(Math.abs(gaussian(0, columns)));
          console.log(rand);
          if (rand < columns) {
            columnIndex = rand
          }
        }
        const rowIndex = Math.floor(Math.random()*rows);
        if (matrix[rowIndex][columnIndex] === 0) {
          matrix[rowIndex][columnIndex] = 1;
          success = true;
        }
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Algorithm 1
    Algorithm 2

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36
Chrome 91 on Windows
View result in a separate tab
Test name Executions per second
Algorithm 1 19323.2 Ops/sec
Algorithm 2 13451.1 Ops/sec