Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
while(true) vs loop
require 'benchmark'
MAX = 10**8
puts Benchmark.measure{
a = MAX
while(true)
a -= 1
break if a == 0
end
}
puts Benchmark.measure{
a = MAX
loop do
a -= 1
break if a == 0
end
}
1.720000 0.000000 1.720000 ( 1.722252)
5.220000 0.000000 5.220000 ( 5.219000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.