Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Fisher-Yates Shuffle
Test implementations from https://twitter.com/oliverjumpertz/status/1434779862955405313
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Nikolay
30.0 Ops/sec
Oliver
8946.1 Ops/sec
Andrea
8424.7 Ops/sec
Script Preparation code:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1) + min); //The maximum is inclusive and the minimum is inclusive } function shuffleOliver(array) { let current; let top; let tmp = (current = top = array?.length); if (!top) { return array; } while (--top) { current = getRandomIntInclusive(0, top); tmp = array[current]; array[current] = array[top]; array[top] = tmp; } return array; }; function shuffleAndrea(array) { let {length} = array; while (length--) { let i = getRandomIntInclusive(0, length); [array[i], array[length]] = [array[length], array[i]]; } return array; }; function shuffleNikolay(array) { const t = array.splice(0, array.length); while (t.length > 0) { const index = getRandomIntInclusive(0, t.length - 1); array.push(t.splice(index, 1)[0]); } return array; }; window.array_10000 = Array.from(Array(10000).keys());
Tests:
Nikolay
shuffleNikolay(window.array_10000);
Oliver
shuffleOliver(window.array_10000);
Andrea
shuffleAndrea(window.array_10000);