There's more than one way to do things PerlMonks

Comment on

 Need Help??
Inspired by BrowserUK's 2nd algorithm but slightly faster, since it calls substr just once in exchange for an extra assignment:
```sub emazep {
my \$s = shift;
my \$tmp;

( (\$tmp = substr \$s, \$_-1, 2) eq '11' or \$tmp eq '00' ) and return
+for @_;

return 1;
}
Using exactly the same benchmark provided here by BrowserUK, it gives:
```          Rate   ysth  japhy matija   buk2   buk1 emazep
ysth    1966/s     --   -17%   -87%   -89%   -89%   -91%
japhy   2361/s    20%     --   -84%   -87%   -87%   -89%
matija 14719/s   648%   523%     --   -19%   -20%   -32%
buk2   18088/s   820%   666%    23%     --    -1%   -17%
buk1   18363/s   834%   678%    25%     2%     --   -16%
emazep 21753/s  1006%   821%    48%    20%    18%     --

Update:

added esialb's (corrected) solution to the BrowserUK's benchamrk:
```          Rate   ysth  japhy matija esialb   buk1   buk2 emazep
ysth    1975/s     --   -17%   -87%   -88%   -89%   -89%   -91%
japhy   2374/s    20%     --   -84%   -85%   -87%   -87%   -89%
matija 15000/s   659%   532%     --    -8%   -17%   -18%   -30%
esialb 16299/s   725%   586%     9%     --   -10%   -11%   -23%
buk1   18156/s   819%   665%    21%    11%     --    -1%   -15%
buk2   18277/s   825%   670%    22%    12%     1%     --   -14%
emazep 21295/s   978%   797%    42%    31%    17%    17%     --

2nd Update:

I've been misleaded by the BrowserUK solution, which contains an error which also slowed down his sub (see here.) After the correction his sub proves to be the fastest (dani_l's very elegant solution also included in the benchmark):
```          Rate   ysth  japhy esialb matija   buk1 dani_l emazep  buk2*
ysth    1845/s     --   -22%   -85%   -87%   -88%   -89%   -90%   -91%
japhy   2366/s    28%     --   -81%   -84%   -84%   -86%   -87%   -88%
esialb 12530/s   579%   430%     --   -14%   -16%   -28%   -31%   -38%
matija 14566/s   689%   516%    16%     --    -2%   -16%   -20%   -28%
buk1   14885/s   707%   529%    19%     2%     --   -14%   -18%   -27%
dani_l 17357/s   841%   634%    39%    19%    17%     --    -5%   -14%
emazep 18181/s   885%   669%    45%    25%    22%     5%     --   -10%
buk2*  20275/s   999%   757%    62%    39%    36%    17%    12%     --
buk2* is the buk2 sub as corrected by me here.

Cheers, Emanuele.

In reply to Re: fast bit twiddling by emazep
in thread fast bit twiddling by spurperl

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

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [1nickt]: Sorry kgb can't help there, not a perltidy user. [marto]: evening all

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-11-18 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (277 votes). Check out past polls.

Notices?