Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Returning first element of an array from a function

by Anonymous Monk
on Mar 17, 2004 at 09:10 UTC ( [id://337261]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Returning first element of an array from a function
in thread Returning first element of an array from a function

Oooooohhhh, but that builds up an entire list for the slicing and can damage performance horrendously:

#!c:/perl/bin/perl -w $|++; use strict; use Benchmark 'timethese'; # make it so we split() into many many elements our $baz = join '', "yes.no.maybe.so." x 5000; timethese(2000, { undef => q{ ($foo, undef, $bar) = split(/\./, $baz); }, splice => q{ ($foo, $bar) = (split(/\./, $baz))[0,2]; } } ); __END__ Benchmark: timing 2000 iterations of splice, undef... splice: 101 wallclock secs (93.86 usr + 0.39 sys = 94.25 CPU) @ +21.22/s (n= 2000) undef: 0 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU) @ 14 +184.40/s ( n=2000) (warning: too few iterations for a reliable count)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found