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 strstr performance of short needles


On Wed, 05 Sep 2018, Wilco Dijkstra wrote:

>Improve strstr performance for the common case of short needles.  For 2-4 
>characters a small loop is typically fastest.  On large strings the speedup
>with a needle size of 4 is about 65%.

I ran some tests on a powerpc64le machine and I noticed that, as the
haystack becomes larger, the search for a needle that is *not* in the
haystack, became slower with this change.

For instance, when the haystack is 32 chars long, searching for a 4 chars
long needle that is not in the haystack [1] took ~11% to ~22% longer to
finish, when compared to the pristine code.  When the needle *is* in the
haystack, that did not happen and the performance was usually 30% better.

In my tests, this is also true for needles 2 and 3 chars long.


Have you observed similar results in your tests?


[1] Tests with the summary similar to this:
      Length   32/4, alignment 0/ 0, fail:


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