[Cascavel-pm] Duvida expressao regular?

Nilson Santos Figueiredo Junior acid06 em gmail.com
Quinta Outubro 18 11:14:02 PDT 2007


On 10/18/07, Alceu Rodrigues de Freitas Junior <glasswalk3r em hotmail.com> wrote:
> <test2>
> use Benchmark qw/cmpthese/;
>
> my $string = 'foobar';
> my $compiled = qr/[13579]($string)?/;
> my $i;
>
> cmpthese(
>     5000,
>     {
>         normal_with_text => sub {
>             for ( 1000 .. 1999 ) { $i++ if /[13579]($string)?/ }
>         },
>         with_o_and_text => sub {
>             for ( 1000 .. 1999 ) { $i++ if /[13579]($string)?/o }
>         },
>         compile_with_qr => sub {
>             for ( 1000 .. 1999 ) { $i++ if /$compiled/ }
>           }
>     }
> );
> </test2>
>
> O resultado foi mais estranho ainda:
>
>                   Rate normal_with_text  with_o_and_text  compile_with_qr
> normal_with_text 713/s               --              -5%             -18%
> with_o_and_text  748/s               5%               --             -14%
> compile_with_qr  865/s              21%              16%               --

Pra mim, as diferenças foram menores neste teste:

                  Rate normal_with_text  with_o_and_text  compile_with_qr
normal_with_text 660/s               --              -3%             -15%
with_o_and_text  681/s               3%               --             -13%
compile_with_qr  780/s              18%              15%               --

> Mais um teste:
>
> <test3>
> use Benchmark qw(cmpthese);
>
> my $string = 'foobar';
> my $compiled = qr/$string/;
> my $i;
>
> cmpthese(
>     200000,
>     {
>         normal_with_text => sub {
>             for ( a .. z ) { $i++ if /$string/ }
>         },
>         with_o_and_text => sub {
>             for ( a .. z ) { $i++ if /$string/o }
>         },
>         compile_with_qr => sub {
>             for ( a .. z ) { $i++ if /$compiled/ }
>           }
>     }
> );
> </test3>
>
> E o resultado foi algo mais razoável (mas a expressão regular foi alterada):
>
>                      Rate  compile_with_qr normal_with_text  with_o_and_text
> compile_with_qr   89485/s               --              -1%             -12%
> normal_with_text  90785/s               1%               --             -11%
> with_o_and_text  101523/s              13%              12%               --

Meus resultados:

                    Rate  compile_with_qr normal_with_text  with_o_and_text
compile_with_qr  83091/s               --              -5%             -12%
normal_with_text 87070/s               5%               --              -7%
with_o_and_text  94118/s              13%               8%               --

Parece que o normal_with_text é proporcionalmente mais rápido no meu
sistema que no seu por algum motivo estranho.

Talvez essa diferença esteja ocorrendo pois estou utilizando um build
anterior do ActivePerl:

This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 33 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 819 [267479] provided by ActiveState http://www.ActiveState.com
Built Aug 29 2006 12:42:41

Rodando em um Athlon 64 3500+ com 1GB de RAM.

-Nilson Santos F. Jr.


Mais detalhes sobre a lista de discussão Cascavel-pm