Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re5: Optimizing a string processing sub

by dragonchild (Archbishop)
on Jan 09, 2003 at 15:11 UTC ( [id://225551]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Optimizing a string processing sub
in thread Optimizing a string processing sub

Very good catch, MarkM!. I didn't really thoroughly test my solution, leaving that as an exercise for the reader.

As for my solution, although this wasn't in the original specs, I also wanted to solve the problem without using some variant of split (which /(.)/g is). However, I'm blanking on it.

Although this may have been posted in the mainline discussion, I'll post this, as it Benchmark's faster than yours.

sub score { my ($x, $y) = @_; return -1 if $x eq $y; my %x; $x{$_}++ for $x =~ /./g; my $score = 0; $x{$_} && $score++ for $y =~/./g; $score; }
For 1 million iterations, this benches at 74.56sec. Yours benches at 122.51sec. :-)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

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

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

    No recent polls found