The below results show there's no difference between the speed of ++$counter & 1 and ++$counter % 2. I thought there might be but I guess not. Oh well.
use Benchmark qw( cmpthese );
use constant ITERATIONS => 50_000_000;
my $counter = 0;
cmpthese( ITERATIONS,
{
and => sub { ++$counter & 1 },
mod => sub { ++$counter % 2 },
},
);
__END__
mod 4761905/s -- -29%
and 6666667/s 40% --
Rate mod and
mod 4366812/s -- -21%
and 5524862/s 27% --
Rate mod and
mod 5524862/s -- -10%
and 6134969/s 11% --
Rate and mod
and 6493506/s -- -29%
mod 9107468/s 40% --
Rate and mod
and 6250000/s -- -14%
mod 7288630/s 17% --
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.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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?
See Writeup Formatting Tips and other pages linked from there for more info.