This is the mail archive of the
mailing list for the GCC project.
Re: Patch to add __builtin_printf -> fputs transformations
- To: bkorb at cruzio dot com
- Subject: Re: Patch to add __builtin_printf -> fputs transformations
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Wed, 20 Sep 2000 12:38:36 -0400 (EDT)
- Cc: gcc-patches at gcc dot gnu dot org
> From: Bruce Korb <firstname.lastname@example.org>
> > Nevertheless, my testing on solaris2.7 indicates that
> > fputs("hello-world\n",stdout) in isolation is about 40% faster than
> > printf("hello-world\n").
> I think this speaks of libc problems. *SOME* additional overhead
> is certainly understandable. 40% (in unrolled loops, I assume)?
> Naw. I suppose I should read code before spouting off, but really?
Of course the libc matters but I see improvement everywhere. Here's a
contrived program written to maximally expose stdio times. (Note
fputs->fwrite is a future builtin opt I plan to submit, its not
currently done but is provided to show that further improvements are
possible.) Compile this with gcc -O2 -funroll-loops:
#define MAX_ITER 5000000
#define STMT(string) fwrite(string,1,__builtin_strlen(string),stdout)
#define STMT(string) fputs(string, stdout)
#define STMT(string) printf(string)
for (i=0; i < MAX_ITER; i++)
STMT ("hello world\n");
I tuned MAX_ITER on each platform so that the program ran for about
5-15 user+sys seconds using printf. That gives me a good S/N ratio
while not filling up my disk. So the numbers are only relatively
meaningful across, not down between arches.
The numbers below were generated using "time a.out > foo".
arch printf fputs fwrite fputs/printf fwrite/printf
---- ------ ----- ------ ------------ -------------
x86-linux 15.11 13.29 7.93 .88 .525
solaris2.7 12.94 8.39 6.98 .64 .539
irix6.2 7.822 5.68 4.879 .73 .624
Solaris seems to benefit the most from the printf->fputs conversion,
it got a 36% drop in this particular test. But look closely at the
glibc-linux drop from printf->fwrite, it almost cut in half.
Kaveh R. Ghazi Engagement Manager / Project Services
email@example.com Qwest Internet Solutions