in reply to Re^2: Producing a list of offsets efficiently
in thread Producing a list of offsets efficiently

Of course wmap() and count() are going to be the slowest, because they go through the string twice: once to split it into individual elements, and again to compare each element to the desired one. The index() approach is very certainly the fastest. I wrote a function called aindex() a long time ago that did just that -- used index to step through a string and return all the indices of a substring in that string.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
  • Comment on Re^3: Producing a list of offsets efficiently

Replies are listed 'Best First'.
Re^4: Producing a list of offsets efficiently
by tlm (Prior) on May 29, 2005 at 17:57 UTC

    Yes, no surprises there on the ordering, though the hard numbers are eloquent; I would not have been able to predict a factor of ∼25 difference between wgrep and windex_1, say.

    the lowliest monk