Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Optimizing the bejeezus out of a sub

by sgifford (Prior)
on Jun 24, 2003 at 07:38 UTC ( #268414=note: print w/replies, xml ) Need Help??


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

My goal was to speed things up by avoiding copying each value from @_ to $section. While foreach is certainly more aesthetic, some benchmarking shows it to be about the same speed as my loop.

I'm a little surprised by this, actually; I expected using @_ directly to always be faster, since it would avoid copying values.

  • Comment on Re: Re: Optimizing the bejeezus out of a sub

Replies are listed 'Best First'.
Re: Re: Re: Optimizing the bejeezus out of a sub
by IlyaM (Parson) on Jun 24, 2003 at 08:55 UTC
    foreach my $section ( @_ ) { ... } doesn't copy value from @_ to $section. In the loop the variable $section is merely an alias to a currently selected element in @_ array. You can even modify @_ array by assigning a new value to $section. Example:

    # adds 1 to all elements of array foreach my $elem (@arr) { $elem ++; }

    --
    Ilya Martynov, ilya@iponweb.net
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
    Personal website - http://martynov.org

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://268414]
help
Chatterbox?
[Discipulus]: might be it is necessary to pass the pic data like MIME::Base64:: encode( data..
[Discipulus]: if you have a jpeg data: or as wise Corion said IM ca n read directly your handle
[Corion]: Meh. I get the feeling I should post a call-to-action for people to test their modules with the upcoming 5.26 (or 5.25.latest), as it seems that the smoke testers don't really weed out modules that fail without . in @INC
[Corion]: But without instructions on how to easily test things yourself, I don't think such a call to arms is helpful
[Corion]: (this post on nntp.perl.org / p5p makes it seem to me that smoke testers seem to have a blind spot there)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-03-27 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (317 votes). Check out past polls.