Fractions are slow in PyPy
This is why the Markov decision process in pyperformance is slower in PyPy.
from time import perf_counter
from fractions import Fraction
def primes(n): # returns first n primes
primes = [2]
i=3
while len(primes)<n:
if all(i%p for p in primes):
primes.append(i)
i+=2
return primes
T=1000
N=1000
a = [Fraction(i)/Fraction(p) for i,p in enumerate(primes(N))] # Worst case CPython: 3.60 secs | PyPy: 142.1 secs
t = perf_counter()
for _ in range(T): sum(a)
print(perf_counter()-t)
a = [Fraction(i)/Fraction(N) for i in range(N)] # Good case CPython: 1.23 secs | PyPy: 0.10 secs
t = perf_counter()
for _ in range(T): sum(a)
print(perf_counter()-t)