in reply to Re: counting the number of 16384 pattern matches in a large DNA sequence
in thread counting the number of 16384 pattern matches in a large DNA sequence

There is no benefit to studying a string more than once.

Just as a matter of curiosity, have you ever come across a case in which there was a benefit from studying a string even once?

Occasionally and informally, I have Benchmark-ed a use of study that I thought might be beneficial per the description in the docs: matching many regexes against a single, unchanging string. I have never seen any benefit. (I must admit I have never tested the specific example given in the perlfunc docs for which a potential "big win" is claimed.) Has regex optimization reached a point at which we can say "... I ain't gonna study [strings] no more"?

  • Comment on Re^2: counting the number of 16384 pattern matches in a large DNA sequence

Replies are listed 'Best First'.
Re^3: counting the number of 16384 pattern matches in a large DNA sequence
by BrowserUk (Patriarch) on Jun 14, 2012 at 18:51 UTC
    Just as a matter of curiosity, have you ever come across a case in which there was a benefit from studying a string even once?

    Yes. But it was

    • a while ago on much slower hardware than I now run.

      Boyer-Moore worked best in the days before the chip manufacturers had built string search algorithms into microcode; and before the advent of deeply pipelined architectures with branch predictions, when branching had a proportionally significantly greater impact on throughput than with modern hardware.

    • the needle being search for contained a character that was very rare in the haystack being searched.

      This allows the algorithm to trade intelligence for brute force.

      With modern processors that overlap fetches and branching stalls with other parts of the opcodes, the benefits are greatly curtailed.

    I tried to look up a old post of mine that benchmarked study having a beneficial effect, but couldn't find it.

    I also tried to replicate my memory of what I was doing back then, but cannot reproduce it. Whether that's because my memory is bad, or my modern processor negates the benefits I'm not totally sure, but I suspect the latter.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?