shuffles

Benchmark created on


Setup

const array = [...Array(1000).keys()];

Test runner

Ready to run.

Testing in
TestOps/sec
i >= 0
for (let i = array.length - 1; i >= 0; i--) {
  const j = Math.floor(Math.random() * (i + 1));
  [array[i], array[j]] = [array[j], array[i]];
}

ready
i >= 1
for (let i = array.length - 1; i >= 1; i--) {
  const j = Math.floor(Math.random() * (i + 1));
  [array[i], array[j]] = [array[j], array[i]];
}

ready
i >= 2
for (let i = array.length; i >= 2; ) {
  const j = Math.floor(Math.random() * i--);
  [array[i], array[j]] = [array[j], array[i]];
}

ready
i
for (let i = array.length; i; ) {
  const j = Math.floor(Math.random() * i--);
  [array[i], array[j]] = [array[j], array[i]];
}

ready

Revisions

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