Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Code Smarter

by tphyahoo (Vicar)
on Nov 08, 2005 at 09:41 UTC ( #506668=note: print w/ replies, xml ) Need Help??


in reply to Code Smarter

Yep, and here's the benchmarks to prove it. (I just felt like learning the benchmark module.)

use strict; use warnings; use Benchmark qw(:all); #banging on the keyboard my $target_string = 'al;nsdfj;oasmfdio;asdfoasdjfm;mioasfdsjdo;fijso;a +dfjmio;sadjfmos;adfmjosia;mdfjiosad'; Benchmark::cmpthese ( 1000000, { 'substituteStar' => sub { $_ = $target_string; s/[abc]*//g; } , 'substituteNoStar' => sub { $_ = $target_string; s/[abc]//g; } , 'substitutePlus' => sub { $_ = $target_string; s/[abc]+//g; } , 'trAbc' => sub { $_ = $target_string; tr/abc//d; } } )
Outputs:
Rate substituteStar substituteNoStar substitutePl +us trAbc substituteStar 29935/s -- -85% -8 +5% -95% substituteNoStar 195733/s 554% -- - +1% -69% substitutePlus 196928/s 558% 1% +-- -68% trAbc 621504/s 1976% 218% 21 +6% --


Comment on Re: Code Smarter
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-07-14 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls