Why shouldn't I use PyPy over CPython if PyPy is 6.3 times faster?

前端 未结 12 1095
暖寄归人
暖寄归人 2020-12-02 03:12

I\'ve been hearing a lot about the PyPy project. They claim it is 6.3 times faster than the CPython interpreter on their site.

Whenever we talk about dynamic languag

12条回答
  •  执笔经年
    2020-12-02 03:49

    I've found examples, where PyPy is slower than Python. But: Only on Windows.

    C:\Users\User>python -m timeit -n10 -s"from sympy import isprime" "isprime(2**521-1);isprime(2**1279-1)"
    10 loops, best of 3: 294 msec per loop
    
    C:\Users\User>pypy -m timeit -n10 -s"from sympy import isprime" "isprime(2**521-1);isprime(2**1279-1)"
    10 loops, best of 3: 1.33 sec per loop
    

    So, if you think of PyPy, forget Windows. On Linux, you can achieve awesome accelerations. Example (list all primes between 1 and 1,000,000):

    from sympy import sieve
    primes = list(sieve.primerange(1, 10**6))
    

    This runs 10(!) times faster on PyPy than on Python. But not on windows. There it is only 3x as fast.

提交回复
热议问题