Skip to content

Instantly share code, notes, and snippets.

@bernEsp
Last active December 18, 2015 22:29
Show Gist options
  • Save bernEsp/5855008 to your computer and use it in GitHub Desktop.
Save bernEsp/5855008 to your computer and use it in GitHub Desktop.
numbers = 100000.times.map { Random.rand(2000) }
t = Time.now
yield
ruby_sort = numbers.sort
p "it tooks #{t-Time.now}s"
#[5, -3, 3, 20, -50, 1, -1, 2]
def bubblesort( collection )
t = Time.now
for i in 0..collection.length-1
collection.each_with_index do |item, index|
break if collection[index + 1].nil?
if item > collection[index + 1]
collection[index] = collection[index + 1]
collection[index + 1] = item
end
end
end
puts "tooks #{t-Time.now}s"
collection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment