Array shuffle

Benchmark created on


Description

Array shuffle methods.

Setup

const n = Math.random()*400|0+50;
let toShuffle = new Array(n).map(()=>Math.random()*10|0);

Test runner

Ready to run.

Testing in
TestOps/sec
Copy array
const copy = [...toShuffle];
const out = [];
while(copy.length > 0){
	out.push(...copy.splice(Math.random()*copy.length|0,1))	
} 
toShuffle = out;
ready
Fisher yates
let m = toShuffle.length;
let i = 0;
while(m>0){
	i = (Math.random()*m--)|0;
	[toShuffle[m], toShuffle[i]] = [toShuffle[i],toShuffle[m]];
}
ready

Revisions

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