Created
October 2, 2017 06:59
-
-
Save thebopshoobop/a2bef405090595ed4ab823ca5c27442e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const benchmark = arr => { | |
arr = arr | |
? arr | |
: [...Array(1000)].map(() => Math.floor(Math.random() * 1000)); | |
const versions = [ | |
{ arr: [...arr], title: "Random" }, | |
{ arr: [...arr.sort((a, b) => a - b)], title: "Sorted" }, | |
{ arr: [...arr.reverse()], title: "Reversed" }, | |
{ arr: new Array(1000).fill(8), title: "Equal" } | |
]; | |
const sorts = [ | |
{ func: bubbleSort, title: "Bubble" }, | |
{ func: quickSort, title: "Quick" }, | |
{ func: radixSort, title: "Radix" } | |
]; | |
for (let { arr, title } of versions) { | |
console.log(`\n${title} Data`); | |
console.log("*******************************"); | |
for (let { func, title } of sorts) { | |
const before = Date.now(); | |
for (let i = 0; i < 1000; i++) { | |
func([...arr]); | |
} | |
console.log(`${title} Sort: ${(Date.now() - before) / 1000}sec`); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment