develooper Front page | perl.perl5.porters | Postings from October 2016

Re: [perl #129802]

Thread Previous | Thread Next
From:
demerphq
Date:
October 30, 2016 08:51
Subject:
Re: [perl #129802]
Message ID:
CANgJU+U1Mayuby34y61oaTDTc9UD=68jP3Jj=041itciNHmJMg@mail.gmail.com
On 29 October 2016 at 09:46, Leszek Dubiel
<leszek.dubiel@dubielvitrum.pl> wrote:
>
> I have tested program below for $ARGV[0] in range of 0 to 2000 (two
> twousand).
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Benchmark 'cmpthese';
>
> my $s = "A"x (2**16 + 5 - $ARGV[0]);
> my $cat = 'B' . $s . 'B';
> my $spr = sprintf "B%sB", $s;
>
> cmpthese(-1, {
>          "assign" => sub { my $i=0; $s =~ /./ while $i++ < 100 },
>          "concat" => sub { my $i=0; $cat =~ /./ while $i++ < 100 },
>         "string" => sub { my $i=0; $spr =~ /./ while $i++ < 100 }
> });
> ########### end
>
>
> During this long run:
>
>        -- "concat" was extremely slow in 500 (five hundred) cases, every
> fourth run -- $ARGV[0] = 0, 2, 4, 8, 12, 16, ...
>
>       -- "assing" was extremely slow for $ARGV[0] =  6,  262,  518, 774,
> 1030,  1286,  1542,  1798, ...
>
>          -- "string" was extremely slow for $ARGV[0] = 8,  264, 520,  776,
> 1032,  1288,  1544,  1800, ...
>
>
>
> My function works on reference to big string, and here is ugly workaround --
> check if program is running extremely slow, and add one space to string in
> that case (15 seconds):
>
> sub ... {
>
> while () {
>
>     my $a = ... # big text
>
>         # matching big text ...
>     use v5.10;
>     state $t = time;
>     if (time > $t + 15) {
>         my $x = pos $$a;
>         $a .= " ";
>         pos $a = $x;
>         $t = time;
>     }
>  }
> }

You have not told us your OS, or the version of Perl you are using,
and I cannot replicate this issue, so it is hard to say much.

Can you please provide the output of perl -V, and details about your os, etc.

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About