TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PyPy faster than C (on a carefully crafted example)

25 pointsby progover 14 years ago

5 comments

grav1tasover 14 years ago
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".<p>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.<p>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).
评论 #2179909 未加载
jwatzmanover 14 years ago
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.<p>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.
评论 #2180158 未加载
burgerbrainover 14 years ago
<i>"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:<p>1000000000.000000<p>real 0m4.396s user 0m4.386s sys 0m0.007s<p>and for gcc -O3 -flto -fwhole-program:<p>1000000000.000000<p>real 0m1.312s user 0m1.308s sys 0m0.003s"</i><p>Yet another case of somebody thinking they're making a clever comparison by forgetting to set their compiler flags properly.
评论 #2180429 未加载
评论 #2180838 未加载
malkiaover 14 years ago
How does it fare to the shootout benchmark game?<p>Here is comparison of pypy and luajit <a href="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&#38;lang=pypy&#38;lang2=luajit" rel="nofollow">http://shootout.alioth.debian.org/u32/benchmark.php?test=all...</a>
minimaxover 14 years ago
I would have liked to see the timing information for PyPy without dynamic inlining.