Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: declaring lexical variables in shortest scope: performance?

by choroba (Archbishop)
on Mar 31, 2020 at 11:27 UTC ( #11114845=note: print w/replies, xml ) Need Help??


in reply to Re^2: declaring lexical variables in shortest scope: performance?
in thread declaring lexical variables in shortest scope: performance?

> it's 50% slower

Do you mean you added the my $z=12; to both the subroutines and the lexical one became 50% slower? I can't reproduce that behaviour. Adding it to only one of the subs slows it (35% in my case), but then we are comparing apples and oranges.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^4: declaring lexical variables in shortest scope: performance?
by bliako (Parson) on Mar 31, 2020 at 11:58 UTC

    I meant to say that comparing lexicals only: one with a my $z; inside the loop is so much slower. Even 35% is much

    here is the code:

    use Benchmark 'cmpthese'; cmpthese(-2, { predecl => ' my $y; my $x; for $x (1..10000) { $y+=$x } #print "$y\n"; ', lexical => ' my $y; for my $x (1..10000) { $y+=$x } #print "$y\n"; ', }); __END__
    Rate predecl lexical predecl 1836/s -- -54% lexical 3996/s 118% --

        what do you mean by aliasing? if you mean accessing complex structures $x->{'a'}->{'b'}->[$loop_index] , I always put the static part of the data structure outside the loop and use that "alias?" inside the loop

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-05-24 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (141 votes). Check out past polls.

    Notices?