Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Code Smarter

by tphyahoo (Vicar)
on Nov 08, 2005 at 09:41 UTC ( [id://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% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-12-03 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found