in reply to Re^3: How Index function works??
in thread How Index function works??
well it was in June, below what I found on my disk:
There is an "X" in the middle of a 52MB string of repeated alphabet letters ($pattern = join "","a".."z")
Depending if you look for "Xabc..xyz" or "abc...xyzX" the different approaches show their strength.
I did more tests which I can't find anymore strongly indicating that index doesn't use Boyer-Moore.
Just vary the position of the "X". I'd be glad if you looked it over. :)
use Time::HiRes qw[ time ]; my $pattern = join "","a".."z"; my $str= $pattern x 1E6 . "X" .$pattern x1E6; $\="\n"; $|=1; print "Length: ",length $str; print "\n---End X"; $start=time; print "Match: ", $str =~/${pattern}X/; printf "\t took %.3f sec\n",time-$start; $start=time; print "Index: ", index $str , "${pattern}X"; printf "\t took %.3f sec\n",time-$start; print "\n---Start X"; $start=time; print "Match: ", $str =~/X${pattern}/; printf "\t took %.3f sec\n",time-$start; $start=time; print "Index: ", index $str , "X${pattern}"; printf "\t took %.3f sec\n",time-$start;
RESULT:
Length: 52000001 ---End X Match: 1 took 0.021 sec Index: 25999974 took 0.263 sec ---Start X Match: 1 took 0.165 sec Index: 26000000 took 0.094 sec
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How Index function works??
by Corion (Patriarch) on Oct 24, 2011 at 09:57 UTC | |
by LanX (Saint) on Oct 24, 2011 at 10:13 UTC |