Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by choroba (Cardinal)
on Mar 31, 2020 at 11:27 UTC ( [id://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 (Monsignor) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-23 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found