Sympy on PyPy - Sometimes 6x faster, sometimes 4x slower
<p>Here, pypy is slower in calculating, whether a given number is prime:</p>

<pre><code>C:\Users\User&gt;python -m timeit -n10 -s"from sympy import isprime" "isprime(2**521-1)"
10 loops, best of 3: 25.9 msec per loop

C:\Users\User&gt;pypy -m timeit -n10 -s"from sympy import isprime" "isprime(2**521-1)"
10 loops, best of 3: 97.9 msec per loop
</code></pre>

<p>Here, pypy is faster in creating a list of primes (from 1 to 1000000):</p>

<pre><code>C:\Users\User&gt;pypy -m timeit -n10 -s"from sympy import sieve" "primes = list(sieve.primerange(1, 10**6))"
10 loops, best of 3: 2.12 msec per loop

C:\Users\User&gt;python -m timeit -n10 -s"from sympy import sieve" "primes = list(sieve.primerange(1, 10**6))"
10 loops, best of 3: 11.9 msec per loop
</code></pre>

<p>Very surprising, hard to understand.</p>

<blockquote>
  <p>âIf you want your code to run faster, you should probably just use PyPy.â â Guido van Rossum (creator of Python)</p>
</blockquote>

<p>Am I missing something?</p>

<p><code>isprime</code> has a fast path for when <code>gmpy</code> is installed. <code>gmpy</code> has bindings to a highly optimized C library, and is probably only installed on CPython.</p>

python performance sympy pypy