News for hackers. Stuff that matters.
Re:PyPy is faster than C, again: string formatting by _delirium on Tuesday August 02, 2011 @03:19PM (#2838358)
Re:

> GCC is unable to inline or unroll the sprintf call, because it sits inside of libc.

If I'm understanding http://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Other-Builtins.h... correctly, sprintf should be handled as a built-in function, rather than linking the libc version, unless you explicitly specify -fno-builtin. In theory that should allow gcc to perform various optimizations; I've seen that happen with printf at least, where e.g. printf-ing a constant string just gets compiled to puts.

Re:PyPy is faster than C, again: string formatting by kingkilr on Tuesday August 02, 2011 @03:25PM (#2838380)
Perhaps it is recognizing it, but it's not doing anything interesting with that knowledge, on my machine GCC emits a call to "__sprintf_chk"
Re:PyPy is faster than C, again: string formatting by pja on Tuesday August 02, 2011 @04:12PM (#2838511)
There's nothing really stopping gcc from doing as well here, since it ought to be able to spot that the format string never changes & roll out a custom sprintf() that doesn't need to parse it every time. However, right now gcc doesn't do that, so it loses to a language implementation that does.

The really sad thing is that using an ostringstream in C++ is even worse, despite the fact that C++ has all the types available to it & doesn't need to parse any format strings at all: Not enough template metaprogramming clearly!