I was making some fibonacci calculations with PyPy, first i started with bigger numbers, PyPy was a little bit faster, but with small numbers it gives nearly the same performance and some cases normal interpreter is much more faster than pypy is there a spesific reason why?
from time import time
def fibonacci(n):
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return a
start = time()
result = fibonacci(5000)
end = time()
print(end-start)
With a small number like 5000 Python is actually faster than PyPy;
Python: 0.0006256103515625
PyPy: 0.0016071796417236328
When it comes to a bigger slightly bigger number like 1.000.000, PyPy is faster than Python
PyPy: 8.567905902862549
Python: 9.79963207244873
But when it comes to a different calculation like:
def sum_in_range(a,b):
c = 0
for i in range(1, a):
for j in range(1, b):
c += i+j
return c
start = time()
result = sum_in_range(100000,100000)
end = time()
print(end-start)
PyPy is 60 times faster than Python
PyPy: 0.1999509334564209
Python: 12.051937103271484