Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Optimizing the bejeezus out of a sub

by BrowserUk (Patriarch)
on Jun 24, 2003 at 13:27 UTC ( [id://268491]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Optimizing the bejeezus out of a sub
in thread Optimizing the bejeezus out of a sub

I said might!

Can you substantiate that the listification is always optimised away?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re: Re: Re: Re: Optimizing the bejeezus out of a sub
by diotalevi (Canon) on Jun 24, 2003 at 13:32 UTC

    No. I verified that the case of for(LIST(@_)){ ... } is optimized away into for(@_){ ... } because that is what is in the original code. I also (since you just asked) tried for(@A,@B), for(@A,@B,1) and in all cases the list op was removed. Maybe the list op shows back up when there is something non-simple to read from - functions and builtins.

      That's good to know, thanks.

      Which version are you checking this on? And do you know if this is a recent change?

      I ask because I had at least one situation where for (@array){...} definitly (seemed to?) caused a very large list to be built. At least, that's what my testing (basically watching the memory grow) showed under 5.6.1.

      Update Seems I didn't keep the script, and I can't seem to reproduce the behaviour either.

      I'm looking now to see if I can locate the program.

      I assume that you're determining this by looking at the opcodes (as is your want:)?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


        That's "wont". Its a different word. I tested this on 5.6.1 withe following programs. In all cases the list op was removed from the execution path (so named as 'ex-list'). Now from the use of pushmark I infer there's some stack muckery so maybe while list() isn't doing anything, perhaps there is some other form of listification going on here. I'm not motivated enough to break out gdb to find out.

        perl -MO=Concise -e 'for(@_){print}' perl -MO=Concise -e 'for(@A,@B){print}' perl -MO=Concise -e 'for(@A,@B,1){print}'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found