Last active
January 24, 2017 14:15
-
-
Save ntijoh-daniel-berg/a479866bfc71f3962e0ab4969949013d 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
require 'benchmark' | |
def slowsort(array:) | |
senap = array.dup #Gör en kopia för att undvika att ändra på ursprungslistan | |
return senap.sort! | |
end | |
def supermegasort(array:) | |
senap = array.dup #Gör en kopia för att undvika att ändra på ursprungslistan | |
return senap.sort! | |
end | |
random_list = [] | |
10000.times do |_| | |
random_list << rand(1..1000000) | |
end | |
Benchmark.bm(20) do |x| | |
x.report('slowsort') { slowsort(array: random_list)} | |
x.report('supermegasort') { supermegasort(array: random_list)} | |
x.report('slowsort') { slowsort(array: random_list)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment