Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ah crap, you beat me to it. :)

Update with a fourth sub based on BrowserUK's suggestion. Gets another 2-5% over mine.

Oops, fixed error in u2 that made it look about 10% faster than it was. New timings too.

use Benchmark qw( cmpthese ) ; my $digits = 2491306578; cmpthese( -5, { u1 => sub{ for ( 0 .. 9 ) { return 0 if $digits !~ /$_/;} return 1 +; }, u2 => sub{ my @x = sort split //, $digits; my $x = join "", @x; $x =~ tr/0-9//s; length $x == 10 ? return 1 : return 0; }, u3 => sub { return 0 if $digits =~ /(\d).*\1/; return 1; }, u4 => sub { return $digits !~ /(.).*\1/; }, } ); __END__
All unique: Rate u1 u2 u3 u4 u1 15504/s -- -75% -95% -95% u2 62910/s 306% -- -78% -78% u3 289343/s 1766% 360% -- -1% u4 291910/s 1783% 364% 1% -- Not Unique: Rate u1 u2 u3 u4 u1 17396/s -- -72% -98% -98% u2 62887/s 262% -- -92% -92% u3 748300/s 4202% 1090% -- -5% u4 783739/s 4405% 1146% 5% --

In reply to Re^2: Determining uniqueness in a string. by thundergnat
in thread Determining uniqueness in a string. by Yzzyx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found