This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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] Improve performance of strcat


On Thu, Sep 11, 2014 at 03:42:31PM -0400, Carlos O'Donell wrote:
> On 08/07/2014 09:27 AM, Wilco Dijkstra wrote:
> > Hi,
> > 
> > This patch improves strcat performance by using strlen and strcpy. Strlen has a fast C
> > implementation, so this improves performance even on targets which don't have an optimized strlen
> > and strcpy - it is 25% faster in bench-strcat. On targets which don't provide an optimized strcat
> > but which do have an optimized strlen and strcpy, performance gain is > 2x.
> 
> What benchmarks did you use to test this performance gain?
> 
> Did you use glibc's microbenchmark?
> 
> What numbers did you get?
> 
Ah same patch that I send like year ago, your question is answered in
quoted email.

Also trying to benchmark C implementations is mostly meaningless, if you
want good performance you need write at least assembly implementation of memcpy,
strlen and strcpy. Optimizing one of these has bigger performance impact
than rest of functions combined and if you do not care about that you do
not have to care about this c implementation as well.

Also in case of strcat its easy to see that no matter how well you
optimize it you cannot get faster than strcpy (dest+strlen (dest), src);
minus constant overhead of like one function call. Reason is that you
could use strcat both as 

strcpy (char *x, char *y) 
{ 
  x[0] = 0;
  return strcat (x, y);
}

and

strlen (char *x)
{
  char y[] = "x";
  return strcat2 (x, y); // where we in assembly replace each write instruction jump that calculates end of string.
}

Now if you got input where strcat is faster than strcpy+strlen pair it
would give you faster strlen or strcpy by using formulas above.


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