Hot Loop in Ruby

Hot loop is a loop that contains very little work and iterates many many times. This will keep one of your CPU cores busy and could go as far as to 100% use (bad).

In Ruby, it is when you use these while, loop, until loops:

i = 0
p Process.pid

while i < 100000000000000000000
  i+= 1
end

Open macOS’s Activity Monitor app and find the Ruby process on CPU tab:

CPU usage of hot loop in ruby

CPU usage of hot loop in ruby