require 'timeout'
def at_most_n_times_per_second n
i = 0
Timeout.timeout 1 do
loop do
break true if (i += 1) == n
yield
end
end
rescue Timeout::Error
i
end
i = 0
print = -> { p i += 1 }
sleep = -> { sleep 0.1 }
p at_most_n_times_per_second 1600, &print
p at_most_n_times_per_second 1600, &sleep