Preprocessing sprintf with literal format string

Latest patch:

sprintf-inline-4.patch

Performance testing

To test the performance of various approaches, I've used a small program that calls sprintf(buf, "%d-%d-%d", a, b, c) in a loop 10 million times.
test programuser time spentDescription
sprintf-glibc5.20vanilla glibc call
sprintf-linux3.16sprintf implementation from the Linux kernel, version 2.6.20.4
sprintf-linux-new3.04sprintf implementation from the Linux kernel, version 2.6.23-rc9
sprintf-gcc0.82normal call to sprintf, but compiled with latest GCC trunk with the above patch applied
sprintf-linux-nop1.04sprintf implementation from Linux 2.6.23-rc9, but the call to "number" subfunction commented out. Note that this produces wrong results. The purpose this test is to demonstrate the overhead of just parsing the format string.
Here are all the test programs and a Makefile to compile them, if you want to test them yourself. To compile sprintf-gcc, you'll need to download latest GCC sources from the SVN repository, apply the patch and compile, and modify the paths in the Makefile.

TODO:


Heikki Linnakangas <heikki.linnakangas@iki.fi.nospam>
Updated: 8.10.2007