News for hackers. Stuff that matters.
Re:PyPy faster than C (on a carefully crafted example) by grav1tas on Friday February 04, 2011 @11:03AM (#2179871)
For fairness sake, I with the author would note the version of the C compiler they used. Otherwise saying PyPy is faster than C is like saying "my 2010 Toyota Prius is faster than a car in a carefully crafted example".

Sorry to sound like a language curmudgeon, but if you're going to make a claim that language x is faster than language y you're treading on thin ice. Languages in and of themselves don't have a whole lot of grounding in reality (especially Python; C has some closer analogues to the machine). That is to say that the devil is always in the details, or in this case the implementation of the compiler. Though my guess is the author of this blog post may not have intended for this small post to be flung across various nerd news sources to invoke the ire of language zealots everywhere.

The fact that the compiler can't inline across file boundaries (which is why PyPy is 'faster' in this case), I would think, is not a limitation of the C language, but rather a limitation of a C compiler (which I assume is GCC).

Re:PyPy faster than C (on a carefully crafted example) by ElliotH on Friday February 04, 2011 @11:13AM (#2179909)
The GCC version has been added to the post. It was "GCC 4.4.5 shipped with Ubuntu Maverick"
Re:PyPy faster than C (on a carefully crafted example) by grav1tas on Friday February 04, 2011 @11:14AM (#2179910)
Awesome, thanks!
Re:PyPy faster than C (on a carefully crafted example) by jwatzman on Friday February 04, 2011 @10:55AM (#2179831)
The PyPy version is faster, as the article and commenters point out, because the PyPy JIT can inline a call across a module boundary. GCC can do something like this with -fwhole-program, but that doesn't work on shared libraries.

Has any work gone into inlining (probably only very simple) functions when linking against a shared library? Something like the "add" function clearly has no side effects if you were to look at the asm in the shared library, but it might be hard for the compiler to figure that out in any more complicated cases... perhaps by adding an annotation to the shared object file? It seems doable, at least.

Re:PyPy faster than C (on a carefully crafted example) by stonemetal on Friday February 04, 2011 @12:11PM (#2180158)
But by definition shared libraries are shared code you are going to load at run time. What if between the time your app was compiled and the time your app was run the add function in the shared library changed? You would have the wrong version of the function inlined.
Re:PyPy faster than C (on a carefully crafted example) by jwatzman on Friday February 04, 2011 @02:57PM (#2180895)
Ah, true... what I said makes no sense. Thanks.
Re:PyPy faster than C (on a carefully crafted example) by stonemetal on Saturday February 05, 2011 @09:09AM (#2183093)
Of course that doesn't speak to the fact that a smarter dynamic loading capability couldn't inline at runtime. That is what they are doing after all.
Re:PyPy faster than C (on a carefully crafted example) by burgerbrain on Friday February 04, 2011 @11:28AM (#2179975)
"I added a printf("%f\n",a) to the end of the file so the compiler wouldn't optimize the whole thing away. On my Cure 2 Duo 2.33Ghz, I got for gcc -O3:

1000000000.000000

real 0m4.396s user 0m4.386s sys 0m0.007s

and for gcc -O3 -flto -fwhole-program:

1000000000.000000

real 0m1.312s user 0m1.308s sys 0m0.003s"

Yet another case of somebody thinking they're making a clever comparison by forgetting to set their compiler flags properly.

Re:PyPy faster than C (on a carefully crafted example) by ehsanul on Friday February 04, 2011 @01:11PM (#2180429)
Please elaborate on what the correct flags would be, for those of use who wouldn't know.
Re:PyPy faster than C (on a carefully crafted example) by burgerbrain on Friday February 04, 2011 @09:07PM (#2182203)
Try reading the comment I just quoted.
Re:PyPy faster than C (on a carefully crafted example) by ehsanul on Friday February 04, 2011 @10:40PM (#2182376)
Oh, oops. Sorry, me and at least 3 others had a collective brain fart it seems. I had first thought you meant that both of those sets of compiler flags weren't quite right.
Re:PyPy faster than C (on a carefully crafted example) by bryanlarsen on Friday February 04, 2011 @02:44PM (#2180838)
Doesn't work if you're using a shared library, though.
Re:PyPy faster than C (on a carefully crafted example) by malkia on Friday February 04, 2011 @11:27AM (#2179970)
How does it fare to the shootout benchmark game?

Here is comparison of pypy and luajit http://shootout.alioth.debian.org/u32/benchmark.php?test=all...

Re:PyPy faster than C (on a carefully crafted example) by minimax on Friday February 04, 2011 @11:38AM (#2180015)
I would have liked to see the timing information for PyPy without dynamic inlining.