Fastest String Search Algorithm.

Phil Blundell pb@pbcl.net
Wed Jun 9 13:48:56 GMT 2021


On Wed, Jun 09, 2021 at 05:48:17PM +0530, Amit Choudhary wrote:
> On Wed, Jun 9, 2021, 5:35 PM Phil Blundell <pb@pbcl.net> wrote:
> 
> >
> > Do you have any representative real-world testcases or statistics that you
> > can share with us?
> 
> 
> I had shared my program earlier which has around 60 KB of text copied from
> Internet.

How representative is this of the way that programs actually use strstr() 
in practice?  Do you have any statistics on that?

> So, if needle is located at the beginning or end of haystack, then strstr()
> will outperform many algorithms.
> 
> The real test for strstr() would be if needle is located in the middle of
> the haystack.

Right.  My question really was: where do we think the needle is, in fact,
located most often?  If the real-world scenario is that the needle often
is at the beginning or the end then optimising for that is the right
thing to do.

Phil


More information about the Libc-alpha mailing list