pypy on windows much slower than linux/mac when using complex number type?

Irmen de Jong irmen.NOSPAM at xs4all.nl
Fri Sep 23 15:50:40 EDT 2016


On 20-9-2016 22:38, Irmen de Jong wrote:
> Hi,
> 
> 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 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)
> 
> 
> Regards
> Irmen de Jong
> 


The problem boiled down to a performance issue in window's 32 bits implementation of the
hypot() function   (which abs(z) uses when z is a complex number type).
The 64 bits windows crt lib version is much faster (on par with what is to be expected
from the linux or osx version), but  unfortunately there's no 64 bits pypy
implementation for windows.
Replacing abs(z) by sqrt(r*r+i*i) avoids the problem and is even faster still.

More details here https://bitbucket.org/pypy/pypy/issues/2401

Cheers
Irmen de Jong




More information about the Python-list mailing list