Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

(crazyinsomniac) Re: convert whitespaces to underscores

by crazyinsomniac (Prior)
on May 26, 2002 at 22:29 UTC ( [id://169439]=note: print w/replies, xml ) Need Help??


in reply to convert whitespaces to underscores

I'd replace $file =~ s/\s+/_/g; with $file =~ y/_//sd; and here is why (this is supposed to be a well known fact)
use Benchmark qw( cmpthese ); cmpthese( 100_000, { 's' => sub { $a='a _ b __ c'; $a=~s/_+//g; }, 'y' => sub { $a='a _ b __ c'; $a=~ y/_//sd; } } ); __END__ Benchmark: timing 100000 iterations of s, y... s: 9 wallclock secs ( 7.18 usr + 0.00 sys = 7.18 CPU) @ 13 +927.58/s (n=100000) y: 2 wallclock secs ( 2.19 usr + 0.00 sys = 2.19 CPU) @ 45 +578.85/s (n=100000) Rate s y s 13928/s -- -69% y 45579/s 227% --

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Replies are listed 'Best First'.
Re: (crazyinsomniac) Re: convert whitespaces to underscores
by Juerd (Abbot) on May 26, 2002 at 23:23 UTC

    (tr/// vs s///)

    It doesn't matter for this script as it doesn't matter for most scripts. This particular script is slow because of forking and filesystem changes. Changing the s/// to a tr/// won't increase the speed notably. Not even for a million MP3 files.

    s///g may not be the best way, but it is certainly not a bad way.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Log In?
Username:
Password:

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

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

    No recent polls found