Skip to content

Instantly share code, notes, and snippets.

@stokarenko
Created December 7, 2015 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stokarenko/a247f3f44997e8fbf31d to your computer and use it in GitHub Desktop.
Save stokarenko/a247f3f44997e8fbf31d to your computer and use it in GitHub Desktop.
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