in reply to Re: Matching simple patterns - is there a faster way?
in thread Matching simple patterns - is there a faster way?
I also did another test where I read a proper HTML file and received similar results. Can you please tell me what you did different?use strict; use Benchmark qw(cmpthese); # A big, sorted list (475254 elements) my @list = ('a'..'zzzz'); ##Put the list into a string my $string = join(/ /, @list); $string .= "\n"; cmpthese(0, { # Looking for a random item in @list with grep index => sub { # A random element in the list my $pattern = 'fqsu fqsv fqsw fqsx fqsy'; my $result = index($string, $pattern); }, # Looking for a random item in @list linearly (with foreach) regex => sub { my $pattern = 'fqsu fqsv fqsw fqsx fqsy'; $string =~ /$pattern/; }, } );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Matching simple patterns - is there a faster way?
by flexvault (Monsignor) on Aug 09, 2012 at 14:15 UTC |