[Rio-pm] Performance

Fernando Oliveira fernandocorrea em gmail.com
Sexta Fevereiro 20 10:50:04 PST 2009


pois é...

perl -MBenchmark=cmpthese -e '

@a = map {"a$_"."b"} 1 .. 150_000;

@b = "a" .. "e";

sub a{
   for my $a (@a){
      for my $b (@b){
         next if $a =~ /^$b/;
      }
   }
}


sub b{
   for my $a (@a){
      next if $a =~ /^a/;
      next if $a =~ /^b/;
      next if $a =~ /^c/;
      next if $a =~ /^d/;
      next if $a =~ /^e/;
   }
}


cmpthese(50, {a => \&a, b => \&b});
'
    s/iter     a     b
a     3.40    --  -98%
b 6.44e-02 5175%    --



2009/2/20 Lucas Mateus <lucasmateus.oliveira em gmail.com>

> Brother, pode ate ser que isso traria um custo, mas não justifica esses
> numeros:
>
> EXEMPLO_1: 10.000 paths/17seg
> EXEMPLO_2: 750.000 paths/22seg
>
> DETALHES: SO RH5 64, 8 GB RAM, 2 Proc Quad Xeon
>
>
>
> On Fri, 20 Feb 2009 15:17:24 -0300, Fernando Oliveira <
> fernandocorrea em gmail.com> wrote:
>
>  Vc está usando um map em contexto void, o map guarda o array de resposta
>> na
>> memoria...
>>
>> 2009/2/20 Lucas Mateus <lucasmateus.oliveira em gmail.com>
>>
>>  Estou em uma situação prática em que tenho um ARRAY com 750.000 itens,
>>> cada
>>> item deve se submeter a 60 RegExp, obtendo match faço um next.
>>>
>>> Os dois codigos abaixo (o mais simples que consegui representar) fazem a
>>> mesma coisa, porem o EXEMPLO_1 tem performance extremamente inferior que
>>> o
>>> EXEMPLO_2.
>>>
>>> Gostaria de saber dos Mongers justificativa para isso. Seria a RegExp
>>> dinâmica ?
>>>
>>>
>>>
>>> EXEMPLO_1
>>> [code]
>>>
>>> my @re;    # lista de RegExp 60 itens
>>> my @paths; # lista de Paths 750.000 itens
>>>
>>> foreach my $path (@paths)
>>> {
>>>  map
>>>  {
>>>     if ($path =~ /^$_$/)
>>>     {
>>>         next;
>>>     }
>>>  } @re
>>> }
>>>
>>> [/code]
>>>
>>>
>>>
>>>
>>>
>>> EXEMPLO_2
>>> [code]
>>> my @paths; # lista de Paths 750.000 itens
>>>
>>> foreach my $path (@paths)
>>> {
>>>  next if ($path =~ /^regex_1$/);
>>>  next if ($path =~ /^regex_2$/);
>>>  next if ($path =~ /^regex_3$/);
>>>  next if ($path =~ /^regex_4$/);
>>>  .
>>>  .
>>>  .
>>>  next if ($path =~ /^regex_60$/);
>>> }
>>>
>>> [/code]
>>>
>>>
>>>
>>>
>>> --
>>> Lucas Mateus
>>> Núcleo de Páginas Rápidas e SEO
>>> Fone: 55 11 3065-9978
>>> MSN: lucasmateus_777 em hotmail.com
>>> _______________________________________________
>>> Rio-pm mailing list
>>> Rio-pm em pm.org
>>> http://mail.pm.org/mailman/listinfo/rio-pm
>>>
>>>
>>
>>
>>
>
>
> --
> Lucas Mateus
> iG - Núcleo de Páginas Rápidas e SEO
>
> Fone: 55 11 3065-9978
> MSN: lucasmateus_777 em hotmail.com
> _______________________________________________
> Rio-pm mailing list
> Rio-pm em pm.org
> http://mail.pm.org/mailman/listinfo/rio-pm
>



-- 
Just another Perl Hacker,
Fernando (SmokeMachine)
http://perl-e.org
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/rio-pm/attachments/20090220/5088b9a7/attachment.html>


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