Test cachingu

Benchmark created on


Setup

const rows = [
{xCoord: 10, yCoord: 10, zCoord:10},
{xCoord: 11, yCoord: 10, zCoord:10},
{xCoord: 12, yCoord: 10, zCoord:10},
{xCoord: 13, yCoord: 10, zCoord:10},
{xCoord: 14, yCoord: 10, zCoord:10},
{xCoord: 15, yCoord: 10, zCoord:10},
{xCoord: 16, yCoord: 10, zCoord:10},
{xCoord: 17, yCoord: 10, zCoord:10},
{xCoord: 18, yCoord: 10, zCoord:10},
{xCoord: 19, yCoord: 10, zCoord:10},
{xCoord: 20, yCoord: 10, zCoord:10},
{xCoord: 21, yCoord: 10, zCoord:10},
{xCoord: 22, yCoord: 10, zCoord:10},
];
const selectedRow = rows[10];

Test runner

Ready to run.

Testing in
TestOps/sec
no caching
let totalDepth = 0;
for (let i = 1; i <= rows.indexOf(selectedRow); i++) {
    const previousRow = rows[i - 1];
    const currentRow = rows[i];

    if (
      currentRow.xCoord === null ||
      currentRow.yCoord === null ||
      currentRow.zCoord === null ||
      previousRow.xCoord === null ||
      previousRow.yCoord === null ||
      previousRow.zCoord === null
    ) {
      break;
    }

    const segmentLength =
      Math.sqrt(
        Math.pow(currentRow.xCoord - previousRow.xCoord, 2) +
          Math.pow(currentRow.yCoord - previousRow.yCoord, 2) +
          Math.pow(currentRow.zCoord - previousRow.zCoord, 2),
      ) || 0;

    totalDepth += segmentLength;
};
ready
caching
let totalDepth = 0;

const currentRowIndex  = rows.indexOf(selectedRow);
for (let i = 1; i <= currentRowIndex ; i++) {
    const previousRow = rows[i - 1];
    const currentRow = rows[i];

    if (
      currentRow.xCoord === null ||
      currentRow.yCoord === null ||
      currentRow.zCoord === null ||
      previousRow.xCoord === null ||
      previousRow.yCoord === null ||
      previousRow.zCoord === null
    ) {
      break;
    }

    const segmentLength =
      Math.sqrt(
        Math.pow(currentRow.xCoord - previousRow.xCoord, 2) +
          Math.pow(currentRow.yCoord - previousRow.yCoord, 2) +
          Math.pow(currentRow.zCoord - previousRow.zCoord, 2),
      ) || 0;

    totalDepth += segmentLength;
};
ready

Revisions

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