Created
December 7, 2015 16:41
-
-
Save stokarenko/a247f3f44997e8fbf31d to your computer and use it in GitHub Desktop.
while(true) vs loop
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' | |
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 | |
} |
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
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