Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Cost of list assignment -

by BrowserUk (Pope)
on Jan 31, 2013 at 09:38 UTC ( #1016269=note: print w/ replies, xml ) Need Help??


in reply to Cost of list assignment -

but wondering if this costs more than than doing it otherways

Yes, measurably so:

@a=1..1e6; cmpthese -3,{ a => q[ @a[ $_-1, $_ ] = @a[ $_, $_-1 ] for 1 .. $#a; ], b => q[ my$t; $t = $a[ $_-1 ], $a[ $_-1 ] = $a[ $_ ], $a[ $_ ] = $ +t for 1 .. $#a; ] };; Rate a b a 1.58/s -- -5% b 1.66/s 5% --

but the difference is tiny, so only becomes significant in inner loops with high iteration factors.

Other times the clarity is worth the cost.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Cost of list assignment -
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-08-29 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls