This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize sprintf(buffer,"foo")



On Tuesday, Jun 24, 2003, at 09:19 US/Eastern, Roger Sayle wrote:



On Mon, 23 Jun 2003, Andrew Pinski wrote:
Here is the result on my laptop (a PowerBook 800MHz G4 running Mac OS X
10.2.6, Darwin 6.6) I used the PPC TimeBase register as the timer, also
I made the buffer size 102400 plus one for the zero:


sprintf 5618
strcpy 21422
strcpy+strlen(buf2) 25291
strlen(strcpy(buf1, buf2)) 25456

As you can see that the sprintf wins over just strcpy (without a even
strlen), the strlen adds about the same time as how long sprintf takes.

Can someone else also confirm these figures? Is the call to strcpy getting inlined badly? What are the times for an equivalent memcpy?

I'm just very confused by these numbers. Has this "bug" been filed with
the Apple folks, or should I consider an optimization that converts calls
to strcpy into calls to sprintf on some platforms? Hopefully, its just
a case where we inline a strcpy where we should be calling the larger but
more efficient system library routine.

Maybe a transformation of strcpy to memcpy with a strlen which seems to have about the same speed as the sprintf.

Thanks,
Andrew Pinski



Thanks to Andrew for doing the timings.


Roger
--





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]