Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: RE: Re: always in quest to eliminate temporary variables

by plaid (Chaplain)
on Jun 16, 2000 at 01:11 UTC ( #18404=note: print w/replies, xml ) Need Help??


in reply to RE: Re: always in quest to eliminate temporary variables
in thread always in quest to eliminate temporary variables

It shouldn't really affect the efficiency much, as you're limitting the split to a maximum of two results returned, and so having a longer string passed to the split won't affect it. Either way, the difference in efficiency will be negligible
use Benchmark; use strict; timethese(1000000, { 'One Liner' => \&one_liner, 'Two Liner' => \&two_ +liner }); sub one_liner { # Stick all variables in the functions, so we can # see if there's any extra overhead for the extra # variable in two_liner. my $text = q/Here is some test text. I don't really know what I'm typing here, but does it really matter? I don't think so. I'm just kind of hitting random keys and stuff/; my $next_line; ($text, $next_line) = split /\n/, $text.$next_line, 2; } sub two_liner { my $text = q/Here is some test text. I don't really know what I'm typing here, but does it really matter? I don't think so. I'm just kind of hitting random keys and stuff/; my($next_line, $pre_next_line); ($text, $pre_next_line) = split /\n/, $text, 2; $next_line = $pre_next_line . $next_line; } Benchmark: timing 1000000 iterations of One Liner, Two Liner... One Liner: 21 wallclock secs (19.85 usr + 0.00 sys = 19.85 CPU) Two Liner: 22 wallclock secs (22.85 usr + 0.00 sys = 22.85 CPU)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2020-06-01 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (12 votes). Check out past polls.

    Notices?