develooper Front page | perl.perl5.porters | Postings from April 2011

RE: perl compiler actually has potential to speedup programs (RE:[PATCH 5.13.11] make store_cop_label exportable)

Thread Previous
From:
Konovalov, Vadim ** CTR **
Date:
April 16, 2011 14:30
Subject:
RE: perl compiler actually has potential to speedup programs (RE:[PATCH 5.13.11] make store_cop_label exportable)
Message ID:
35BF8D9716175C43BB9D67CA60CC345E27ADAFFD@FRMRSSXCHMBSC2.dc-m.alcatel-lucent.com
> From: Konovalov, Vadim (Vadim)** CTR ** 
> > From: Konovalov, Vadim (Vadim)** CTR ** 
> > To: 'Jan Dubois'; 'Perl5 Porters Mailing List'
> 
> > > > Actually, I very much think that this - precompiling of 
> > > > perl modules - is underestimated.
> > 
> > > I'll be happy to see some actual evidence of this.  So far 
> > > the benchmarks
> > > for loading bytecode were always disappointing...
> > 
> > its disappointing to have this conclusion :(
> > How come - python saves by pre-compiling, but perl compiler 
> > is so efficient
> > that precompiling isn't do speed improvement....
> > 
> > ok, I'll see if I am capable on doing some numbers...
> > will let you know on results.
> 
> not that I have real numbers,
> but some feed for thoughts, anyway.
> 
> Recently I've came accross my own old code (from 5.8.3 era), which
> basically fills some hash, say, %::inc, with HERE-string values.
> 
> Initially it was just
> %::inc = (
> STRING1 => <<'VKEOP',
> ....
> VKEOP
> );
> 
> I was not satisfied with execution speed, because it took several 
> seconds to parse. Next, I come with this solution: I get required
> code into $uff scalar, and then get it parsed with following code:
> 
> #simple but slow: eval $uff;
> #let's help to parse our stuff
> #%::inc = $uff=~/^'([\w.\\\/]+)' => <<'VKEOP',\n(.*?)^VKEOP/msg;
> #even more faster
> $::inc{$1}=$2 while $uff=~/^'([\w.\\\/]+)' => 
> <<'VKEOP',\n(.*?)^VKEOP/msg;
> 
> This gave me considerable gain.
> 
> Now I've tried this once again.
> Here is the script measuring basically that mechanics:
> 
> use Benchmark ':all';
> 
> my $uff = "%a = (".
> "
> str_i => <<'FOOBAR',
> ".
> ("-" x 80 . "\n")  x 36000 # some lines of 
> ."
> FOOBAR
> " x 500 .
> ")";
> 
> cmpthese( 1000, {
>   'eval' => sub {eval $uff;},
>   'regexp' => sub {%a = $uff=~/^'([\w.\\\/]+)' => 
> <<'FOOBAR',\n(.*?)^FOOBAR/msg;},
>   'loop' => sub {$a{$1}=$2 while $uff=~/^'([\w.\\\/]+)' => 
> <<'FOOBAR',\n(.*?)^FOOBAR/msg;},
> });
> 
> __END__
> 
>          Rate   eval regexp   loop
> eval   36.9/s     --   -96%   -96%
> regexp  955/s  2491%     --     0%
> loop    955/s  2491%     0%     --

sorry, the was a bug,
and after fixing it the picture is even more convincing:

use Benchmark ':all';

my $uff = "%a = (".
( "
str_i => <<'FOOBAR',
". 
("-" x 80 . "\n")  x 360 # some lines of 
."
FOOBAR
" ) x 50 .
")";

cmpthese( 1000, {
  'eval' => sub {eval $uff;},
  'regexp' => sub {%a = $uff=~/^'([\w.\\\/]+)' => <<'FOOBAR',\n(.*?)^FOOBAR/msg;},
  'loop' => sub {$a{$1}=$2 while $uff=~/^'([\w.\\\/]+)' => <<'FOOBAR',\n(.*?)^FOOBAR/msg;},
});


         Rate   eval   loop regexp
eval   10.4/s     --  -100%  -100%
loop   2778/s 26671%     --    -0%
regexp 2786/s 26745%     0%     --


> 
> Its easy to see why I "helped" perl to parse my actually simple hash
> assignment program.
> 
> 
> > > Or on a more positive
> > > note: the Perl compiler seems to be a lot faster than people 
> > > realize. :)
> 
> Still, parsing takes time, that sometimes could sum into noticeable
> value, and it could be a gain to find a workaround.
> 
> The fact that B::C is not gaining enough speed - may be it needs some
> fine-tuning?
> IMO Byteloader is currently suboptimal and stupid: it uses filter, and
> also read by one byte.
> 
> > 
> > I was always impressed by compiler speed.
> > I really am.
> > This is a gold inheritance that we have since 5.003-pre era, 
> > where much attention was spent into performance.
> > 
> > Nowadays I see that every PAR executable includes 
> > Math::BigInt due to dependancies tree, and this is no good.
> > At first, I was glad Math::BigInt to go into the core, but 
> > its actual usage made big disappointment to me.
> 
> Still very true, IMO.
> 
> Regards,
> Vadim.
> 
Thread Previous


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