https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81657

--- Comment #15 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #13)
> (In reply to Wilco from comment #12)
> 
> > > 
> > > Do you have data to show that?
> > 
> > Yes, on x64 I get these timings for a simple function containing just the
> > library call:
> > 
> > size  1024 - 13845 21025 14449 (rawmemchr/memchr/strlen)
> 
> On Skylake/x86-64, I got
> 
> strlen:
> 
> Length 1024, alignment  0:    178.781
> Length 1024, alignment  7:    162.625
> Length 1024, alignment 10:    161.969
> 
> strchr:
> 
> Length 1024, alignment in bytes  0:   83.7812
> Length 1024, alignment in bytes  6:   82.0938
> 
> strchr is 2X faster.  It uses a very different algorithm. I will
> check if I can fold strlen into strchr.

I don't think it's safe to compare different benchmark results like that. But
yes the kernel for both should be very similar. The key difference is that
strchr needs 2x the number of comparisons, which is why an optimized strlen
will always be faster than strchr.

Reply via email to