Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: A mod2 Machine.

by zork42 (Monk)
on Jul 10, 2013 at 10:37 UTC ( #1043442=note: print w/replies, xml ) Need Help??

in reply to A mod2 Machine.

I wonder how the speed of
my $n = 534587; print "even\n" if($n % 2 == 0); # modulo operator of possibly a flo +at or possibly an integer (*)
compares with
use integer; my $n = 534587; print "even\n" if($n & 1 == 0); # checking LSB with Bitwise And on +an integer
(*) perlop: Integer-Arithmetic says
"By default, Perl assumes that it must do most of its arithmetic in floating point."


Also I wonder how this
my $n = "534587"; print "even\n" if($n =~ /[02468]$/); # reg exp
compares with:
my $n = "534587"; my $c = substr($n, -1, 1); # last char print "even\n" if ( ($c == '0') || ($c == '2') || ($c == '4') || ($c = += '6') || ($c == '8') ); # no regexp

Replies are listed 'Best First'.
Re^2: A mod2 Machine.
by choroba (Chancellor) on Jul 10, 2013 at 11:35 UTC
    Use Benchmark to find out.

    Also, using floats to compute modulo does not seem reasonable to me.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I was just about to say that! zork42 please do benchmark it and post the results. PS: I'm really very lazy to do that and plus I'm busy perusing the perldoc's PerlRE tutorial. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043442]
[stevieb]: I'll see how to get in touch with someone and advise that there's an issue. Thanks for helping me confiirm pryrt!
[pryrt]: also mismatches; but matches their sha1
[pryrt]: The mismatched ones have a Jan 23 2017 Last-Modified header -- I wonder if they rezipped them and forgot to update the sha1
[stevieb]: RT ticket for the csum mismatch of various versions of Strawberry Perl

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-03-29 21:06 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.