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

2016-09-24 Thread Christian Gollwitzer

Am 23.09.16 um 21:50 schrieb 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.


Interesting! Now beware that a "real" hypot function does approximately 
the following:


def myhypot(r, i):
if abs(r)>abs(i):
  c = i/r
  return abs(r)*sqrt(1+c*c)
else:
  if i==0:
return 0.0
  else:
c=r/i
return abs(i)*sqrt(1+c*c)


it can well be, that the old 32bit MSVCRT does simply that, which 
requires some floating point ops, whereas the more modern 64bit lib uses 
hand-tuned SSE to perform the equivalent. Just for fun, you could try 
this hypot to see how it performs.



Christian
--
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-23 Thread Irmen de Jong
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

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-21 Thread Irmen de Jong
On 21-9-2016 1:20, Chris Kaynor wrote:

> 
> Regarding the performance decrease, it may be worthwhile to push the report
> to a PyPy specific forum - a PyPy developer will probably see it here, but
> you may get a faster response on a forum specific to PyPy.


You're right.
I don't know the best place for that, but I've made a bug report about it here:
https://bitbucket.org/pypy/pypy/issues/2401


Irmen

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-20 Thread Chris Kaynor
On Tue, Sep 20, 2016 at 3:59 PM, Chris Angelico  wrote:

> On Wed, Sep 21, 2016 at 8:50 AM, Irmen de Jong 
> wrote:
> >> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a
> >> 64-bit Windows. I could well imagine that that has some odd
> >> significance.
> >>
> >> ChrisA
> >
> >
> > Perhaps. Though I can't really imagine what's going on there then. The
> one on Linux is
> > 32 bits as well and it's also much faster...
> > Unfortunately there's no 64 bits pypy expected for windows, so I can't
> test that
>
> Yeah, but the Linux one is running in a 32-bit OS. I don't know how
> the "32-bit on 64-bit" subsystem of Windows works and how fast it is;
> it could be that the thunking defeats some optimizations relating to
> floating-point. Who knows. Hard to test.
>

WoW64 shouldn't have any measurable speed decrease. I've run plenty of
32-bit games on a 64-bit Windows (many games are still 32-bit only), and
they always perform fine, regardless of whether they are CPU or GPU bound
based off the profiling I've done. I think most of the cost is paid in the
context switches.

Regarding the performance decrease, it may be worthwhile to push the report
to a PyPy specific forum - a PyPy developer will probably see it here, but
you may get a faster response on a forum specific to PyPy.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-20 Thread Chris Angelico
On Wed, Sep 21, 2016 at 8:50 AM, Irmen de Jong  wrote:
>> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a
>> 64-bit Windows. I could well imagine that that has some odd
>> significance.
>>
>> ChrisA
>
>
> Perhaps. Though I can't really imagine what's going on there then. The one on 
> Linux is
> 32 bits as well and it's also much faster...
> Unfortunately there's no 64 bits pypy expected for windows, so I can't test 
> that

Yeah, but the Linux one is running in a 32-bit OS. I don't know how
the "32-bit on 64-bit" subsystem of Windows works and how fast it is;
it could be that the thunking defeats some optimizations relating to
floating-point. Who knows. Hard to test.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-20 Thread Irmen de Jong
On 20-9-2016 22:43, Chris Angelico wrote:
> On Wed, Sep 21, 2016 at 6:38 AM, Irmen de Jong  wrote:
>>  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?
> 
> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a
> 64-bit Windows. I could well imagine that that has some odd
> significance.
> 
> ChrisA


Perhaps. Though I can't really imagine what's going on there then. The one on 
Linux is
32 bits as well and it's also much faster...
Unfortunately there's no 64 bits pypy expected for windows, so I can't test that

Irmen


-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-20 Thread Chris Angelico
On Wed, Sep 21, 2016 at 6:38 AM, Irmen de Jong  wrote:
>  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?

Dunno if it's the cause or not, but you're running a 32-bit PyPy on a
64-bit Windows. I could well imagine that that has some odd
significance.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list