From: Ch Lamprecht on
James Taylor schrieb:
> Tad McClellan <tadmc(a)augustmail.com> wrote:
>
>
>>James Taylor <usenet(a)oakseed.demon.co.uk.invalid> wrote:
>>
>>
>>>my ($dir, $leaf) = $path =~ m|^(.*)/(.*)|;
>>
>> ^
>> ^
>>
>>That anchor serves no useful purpose, so it probably shouldn't be there.
>
> The reason it is there is to ensure that the match fails in
> linear time if there is no slash in the $path.
>

However, for strings without slashes, the pattern with the anchor will
be (a little) slower than without the anchor.

(If anybody want's to know ;) )


use warnings;
use strict;
use Benchmark qw(cmpthese) ;

my $string = "a_string_with_or_without_slashes";
my $string2 = "a_string_with_or/without_slashes";
cmpthese(1000000, {
'anchor' => sub{my($foo,$bar)=$string =~ m|^(.*)/(.*)|},
'no_anchor' => sub{my($foo,$bar)=$string =~ m|(.*)/(.*)|},
'an+/' => sub{my($foo,$bar)=$string2 =~ m|^(.*)/(.*)|},
'no_an+/' => sub{my($foo,$bar)=$string2 =~ m|(.*)/(.*)|} });


prints:

Rate no_an+/ an+/ anchor no_anchor
no_an+/ 275028/s -- -1% -83% -84%
an+/ 278164/s 1% -- -83% -84%
anchor 1636661/s 495% 488% -- -5%
no_anchor 1721170/s 526% 519% 5% --

Btw: Is there an expression like 'peacounting' in english ??

Christoph
--
please reply to

perl -e "print scalar reverse q/ed.bew(a)thcerpmal.hpotsirhc/"
From: Ch Lamprecht on
James Taylor schrieb:
> Tad McClellan <tadmc(a)augustmail.com> wrote:
>
>
>>James Taylor <usenet(a)oakseed.demon.co.uk.invalid> wrote:
>>
>>
>>>my ($dir, $leaf) = $path =~ m|^(.*)/(.*)|;
>>
>> ^
>> ^
>>
>>That anchor serves no useful purpose, so it probably shouldn't be there.
>
> The reason it is there is to ensure that the match fails in
> linear time if there is no slash in the $path.
>

However, for strings without slashes, the pattern with the anchor will
be (a little) slower than without the anchor.

(If anybody want's to know ;) )


use warnings;
use strict;
use Benchmark qw(cmpthese) ;

my $string = "a_string_with_or_without_slashes";
my $string2 = "a_string_with_or/without_slashes";
cmpthese(1000000, {
'anchor' => sub{my($foo,$bar)=$string =~ m|^(.*)/(.*)|},
'no_anchor' => sub{my($foo,$bar)=$string =~ m|(.*)/(.*)|},
'an+/' => sub{my($foo,$bar)=$string2 =~ m|^(.*)/(.*)|},
'no_an+/' => sub{my($foo,$bar)=$string2 =~ m|(.*)/(.*)|} });


prints:

Rate no_an+/ an+/ anchor no_anchor
no_an+/ 275028/s -- -1% -83% -84%
an+/ 278164/s 1% -- -83% -84%
anchor 1636661/s 495% 488% -- -5%
no_anchor 1721170/s 526% 519% 5% --

Btw: Is there an expression like 'peacounting' in english ??

Christoph
--
please reply to

perl -e "print scalar reverse q/ed.bew(a)thcerpmal.hpotsirhc/"
From: James Taylor on
Ch Lamprecht <christoph.lamprecht.no.spam(a)web.de> wrote:

> Btw: Is there an expression like 'peacounting' in english ??

Yes, almost the same, it's "bean counting".

--
James Taylor