Skip to content

Instantly share code, notes, and snippets.

@ntijoh-daniel-berg
Last active January 24, 2017 14:15
Show Gist options
  • Save ntijoh-daniel-berg/a479866bfc71f3962e0ab4969949013d to your computer and use it in GitHub Desktop.
Save ntijoh-daniel-berg/a479866bfc71f3962e0ab4969949013d to your computer and use it in GitHub Desktop.
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