News for hackers. Stuff that matters.
Re:PyPy is faster than C, again: string formatting by eridius on Tuesday August 02, 2011 @03:58PM (#2838477)
Sounds like this would be the equivalent of some theoretical

    exp = CompileSprintfFormat("%d %d");
    for (i = 0; i < 10000000; i++) {
        RunCompiledSprintf(exp, i, i);
    }
All I'm really getting out of this is that PyPy now compiles sprintf formats for you and saves the results, and that there's no equivalent API in libc.
Re:PyPy is faster than C, again: string formatting by TylerE on Tuesday August 02, 2011 @04:25PM (#2838564)
That's not really it. This, at least in my understanding, is a fully generic optimization, of operations on constant strings.
Re:PyPy is faster than C, again: string formatting by eridius on Tuesday August 02, 2011 @05:01PM (#2838684)
From the article:

> In the case of PyPy, we specialize the assembler if we detect the left hand string of the modulo operator to be constant.

So it's very much a targeted optimization at the modulo operator (which is Python's equivalent of sprintf).

Re:PyPy is faster than C, again: string formatting by kingkilr on Tuesday August 02, 2011 @07:18PM (#2839097)
I wouldn't say it's particularly targeted, let me show you the code that makes this happen: https://bitbucket.org/pypy/pypy/src/unroll-if-alt/pypy/objsp...
Re:PyPy is faster than C, again: string formatting by pja on Wednesday August 03, 2011 @05:37AM (#2840433)
Yeah, the point is that by expressing the algorithm in Python, the JIT gets to go hog wild optimising tight loops like this one.

Which is great: why do all that work writing some kind of custom sprintf generating function when you can just let the JIT do it for you on the fly?

Re:PyPy is faster than C, again: string formatting by greyfade on Tuesday August 02, 2011 @05:32PM (#2838799)
In that case, wouldn't it be more fair to compare it to a C++ re-implementation of sprintf using the new `constexpr` keyword?
Re:PyPy is faster than C, again: string formatting by DasIch on Tuesday August 02, 2011 @04:42PM (#2838622)
You shouldn't have to use such an API though and this case could be optimized by any C compiler.