Try:
def fib1 a, b = 0, 1 while b < 9999**4000 a, b = b, a+b end puts "\tdone !" end def fib2 a, b = 0, 1 value = 9999**4000 while b < value a, b = b, a+b end puts "\tdone !" end
There will be no difference!
The reason is that in your first test, ruby computes 9999**4000 inside the method you are calling, while in the second test you use a constant that is calculated outside (before running Benchmark), and therefore your second result shorter for '9999 ** 4000' calculation time.
UPDATE: Well, there really is a huge difference between the two tests, and the ruby calculates 9999 ** 4000 in timelessness - see @JorgWMittag's comments below.
I do not delete this answer to save comments.
source share