Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

RE: (bbq) Re(4): Another flatfile thingy

by btrott (Parson)
on Aug 05, 2000 at 00:17 UTC ( [id://26260]=note: print w/replies, xml ) Need Help??


in reply to (bbq) Re(4): Another flatfile thingy
in thread Another flatfile thingy

Doing it in two steps is more efficient. From perlfaq4:
It is much better faster to do this in two steps: $string =~ s/^\s+//; $string =~ s/\s+$//; Or more nicely written as: for ($string) { s/^\s+//; s/\s+$//; }
Here's a benchmark:
use Benchmark; timethese(500_000, { one => sub { my $foo = " perl monks "; $foo =~ s/^\s+|\s+$//g; }, two => sub { my $foo = " perl monks "; for ($foo) { s/^\s+//; s/\s+$//; } }, });
And here are the results:
Benchmark: timing 500000 iterations of one, two... one: 11 secs (11.75 usr 0.00 sys = 11.75 cpu) two: 8 secs ( 7.57 usr 0.00 sys = 7.57 cpu)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-23 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found