[Moscow.pm] Склеивание строк в perl5.8

Denis Evdokimov evdokimov.denis на gmail.com
Пт Окт 24 09:44:52 PDT 2008


Мне кажется, что тест не полон без этих вариантов
А с ними складывается другая картина

           Rate     array   array_2   perl io    concat perl io_2
array     208/s        --      -33%      -39%      -52%      -69%
array_2   310/s       49%        --       -9%      -28%      -54%
perl io   340/s       63%       10%        --      -21%      -49%
concat    432/s      107%       39%       27%        --      -36%
perl io_2 673/s      223%      117%       98%       56%        --


use Benchmark qw(:hireswallclock cmpthese);

my @test_data = (
   'a' x 17,
   'b' x 19,
   'c' x 23,
   'd' x 29,
   'e' x 31,
   'f' x 37,
   'g' x 41,
   'h' x 43,
   'j' x 47,
);

cmpthese(
   3000, {
       'concat' => sub {
           my $scalar_c = '';
           for (my $i=0; $i < 1000; $i++) {
               foreach (@test_data) {
                   $scalar_c .= $_;
               }
           }
           return $scalar_c;
       },
       'array' => sub {
           my @a = ();
           for (my $i=0; $i < 1000; $i++) {
               foreach (@test_data) {
                   push @a, $_
               }
           }
           return join '', @a;
       },
       'array_2' => sub {
           my @a = ();
           for (my $i=0; $i < 1000; $i++) {
               push @a, @test_data;
           }
           return join '', @a;
       },
       'perl io' => sub {
           my $scalar_io = '';
           open(my $fh, '>', \$scalar_io);
           for (my $i=0; $i < 1000; $i++) {
               foreach (@test_data) {
                   print $fh $_;
               }
           }
           close $fh;
           return $scalar_io;
       },
       'perl io_2' => sub {
           my $scalar_io = '';
           open(my $fh, '>', \$scalar_io);
           for (my $i=0; $i < 1000; $i++) {
               print $fh @test_data;
           }
           close $fh;
           return $scalar_io;
       },
   }
);
----------- следущая часть -----------
Вложение в формате HTML было извлечено&hellip;
URL: <http://mail.pm.org/pipermail/moscow-pm/attachments/20081024/8250b874/attachment.html>


Подробная информация о списке рассылки Moscow-pm