Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Re: Re: array pre-allocation trick

by Anonymous Monk
on Nov 02, 2002 at 00:24 UTC ( [id://209866]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: array pre-allocation trick
in thread array pre-allocation trick

True the map doesn't do much, but it's a minimal benchmark for Aristotle's suggestion:
my @array = map { do_stuff_with($_); $_ } 1 .. 5000;
I've replaced "do_stuff_with($_)" with a no-op. It didn't perform as well as the others, so that leads me to think I shouldn't pursue using map in this case.

Replies are listed 'Best First'.
Re^5: array pre-allocation trick
by Aristotle (Chancellor) on Nov 02, 2002 at 06:52 UTC
    That very much depends on your setup. map can be the faster, slower or equal variant. There's too many constraints that play a role - you can't just say "this is faster" based on a minimal benchmark because the characteristics of each looping approach lend themselves to different data structure and control flow designs. If you take a forish approach, using map instead will be awkard - but the same is true in the reverse case.

    Makeshifts last the longest.

Log In?
Username:
Password:

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

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

    No recent polls found