This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Improve strstr performance of short needles
- From: "Gabriel F. T. Gomes" <gabriel at inconstante dot eti dot br>
- To: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, nd <nd at arm dot com>
- Date: Fri, 28 Sep 2018 18:30:18 -0300
- Subject: Re: [PATCH] Improve strstr performance of short needles
- References: <DB5PR08MB1030D79438AF0E17282F3E1783020@DB5PR08MB1030.eurprd08.prod.outlook.com>
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: