[pypy-issue] Issue #2401: complex number calculations much slower on windows than on linux/osx? (pypy/pypy)

Irmen de Jong issues-reply at bitbucket.org
Wed Sep 21 13:02:04 EDT 2016


New issue 2401: complex number calculations much slower on windows than on linux/osx?
https://bitbucket.org/pypy/pypy/issues/2401/complex-number-calculations-much-slower-on

Irmen de Jong:

(copied from message posted to comp.lang.python)

I've stumbled across a peculiar performance issue with Pypy across some different
platforms. It was very visible in some calculation heavy code that I wrote that uses
Python's complex number type to calculate the well-known Mandelbrot set.

Pypy running the code on my Windows machine is doing okay, but when running the same
code on Pypy on different systems, the performance difference is so big it is not even
funny. The other implementations are MUCH faster than the windows one. Which is quite
unexpected because the other machines I've tested on have the same or much lower
physical CPU specs than the windows machine.  Here's the comparison:

Machine specs:

* Windows: 64 bits Windows 7, Intel Core 2 Quad 3.4 Ghz
* Linux: 32 bits Mint 18, Virtualbox VM on above windows machine
* Mac mini: OS X 10.11.6, Intel Core 2 Duo 2.53 Ghz

The 'iterations' function mentioned below is looking like this:

```python
def iterate():
    print("iterating...")
    z = .1+.1j
    c = z
    for _ in range(12345678):
        z = z*z + c
        z = z*z + c
        z = z*z + c
        z = z*z + c
        z = z*z + c
        z = z*z + c
        if abs(z) > 2:
            raise ValueError("should not go towards infinity")
print(abs(z))
```
Rest of the test code I've been using is here:
 https://gist.github.com/irmen/c6b12b4cf88a6a4fcf5ff721c7089078

Test results:

```
#!

                      function:  mandel   / iterations
 Mac mini, Pypy 5.4.1 (64-bit):  0.81 sec / 0.65 sec
 Linux, Pypy 5.1 (32-bit):       1.06 sec / 0.64 sec
 Windows, Pypy 5.4.1 (32-bit):   5.59 sec / 2.87 sec
```



What could cause such a huge difference?

Is it perhaps a compiler issue (where gcc/clang are MUCH better at optimizing certain
things, although I wonder how much of a factor this is because Pypy is doing JITting by
itself as far as I am aware)?   Or is something strange going on with the way the
complex number type is implemented?   (the difference doesn't occur when using only floats)





More information about the pypy-issue mailing list