There's a better way to run that benchmark - using the benchmark-ips
tool which is designed carefully to allow for optimising implementations of Ruby to do their work and will allow for the JIT to warm up.
require 'benchmark/ips'
def calculate(a, b, n = 40_000_000)
i = 0
c = 0
while i < n
a = a * 16807 % 2147483647