News for hackers. Stuff that matters.
Re:Python Is Not C: Take Two by wyldfire on Thursday December 17, 2015 @10:26AM (#10751970)
This is a useful walk through optimization in python.

> The lesson is clear: do not write Python code as you would do in C. Use numpy array operations rather than iterate on arrays. For me it meant a mental shift.

I think the lesson is that "performance critical software requires attention to very many specific details." Using a garbage collected language that allocates objects on the heap by default means that you'll have to take special steps to change the default behavior of the system. You will see very similar behavior with C++, Java, etc.

> I didn't use Pypy so far because it only supports part of Numpy, and not Pandas, Scipy, and Sklearn. It may be that Pypy supports enough of Numpy to run my closest distance code though. If that's the case, then I'll blog about it soon.

I'll confess, I was eagerly waiting the pypy results. IMO using pypy means I get the best of both worlds: more code that can be naively python with python idioms and still yield sufficient performance. For critical algorithms where I can't hit sufficient performance, it's appropriate to use cffi or something to optimize.

Re:Python Is Not C: Take Two by notalaser on Thursday December 17, 2015 @01:33PM (#10753331)
> The lesson is clear: do not write Python code as you would do in C. Use numpy array operations rather than iterate on arrays. For me it meant a mental shift.

That's true in C as well. If you're writing performance-critical code, you use things like BLAS and LAPACK (possibly even the optimized, often parallel versions supplied by your compiler vendor).

Re:Python Is Not C: Take Two by jfpuget on Thursday December 17, 2015 @10:31AM (#10752005)
Thank you, you made Pypy move higher on my todo list.

You have a good point about gc and memory layout. That's why I like C or C++ when writing high performance software. You can control memory locality more easily than with other languages.

Re:Python Is Not C: Take Two by ngoldbaum on Thursday December 17, 2015 @12:58PM (#10753049)
Sure, but what if my work depends on a library that uses C extensions that isn't supported by pypy? Any of the scikits, for example.
Re:Python Is Not C: Take Two by wyldfire on Thursday December 17, 2015 @01:42PM (#10753414)
Unfortunately I have no answer for those. For now scikit and pypy seem mutually exclusive.