while true
instead of loop
RB-P1002loop
can be upto 3x times slower than using while true
for unbounded loops.
def slow
index = 0
loop do
break if index > NUMBER
index += 1
end
end
def fast
index = 0
while true
break if index > NUMBER
index += 1
end
end
loop
vs while true
benchmark: fast-ruby)[https://github.com/fastruby/fast-ruby#loop-vs-while-true-code]