'My indexing' broken by 3.07

Ralph Corderoy ralph at inputplus.co.uk
Sat Dec 16 06:35:40 PST 2017


Hi Charles,

> > Yes.  `^' also suffices.
>
> Interesting. I wonder if 'match beginning of the line' is less
> expensive internally?

Perl's regexp engine is historically extremely good at spotting
optimisations, and some of those details can be seen with its -D option
if perl is compiled suitably, e.g. /x.*foo$/ might decide the minimum
length is four and it must end with `foo' before attempting to find an
`x'.

But in this case, I think `^' is cheaper.

    $ for p in ^ '.*'; do
    >     for n in 100 1000 10000; do
    >         seq $n |
    >         perf stat -e instructions \
    >             perl -ne "/$p/"
    >     done
    > done |&
    > grep instructions:u
             2,588,069      instructions:u                                              
             4,947,485      instructions:u                                              
            28,715,945      instructions:u                                              
             2,600,183      instructions:u                                              
             5,089,466      instructions:u                                              
            30,189,787      instructions:u                                              
    $

Re-arranged, that's

         n         /^/        /.*/        /.*/
       100   2,588,069   2,600,183     +12,114
     1,000   4,947,485   5,089,466    +141,981
    10,000  28,715,945  30,189,787  +1,473,842

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy



More information about the get_iplayer mailing list