Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Actually i think i read it in Mastering Algorithms with Perl even though i cannot find it right now.

Anyway to wipe out your doubts you can try a benchmark:

#!/usr/bin/perl use strict; use Benchmark qw(:all); cmpthese(10, { 'eq' => sub { for (my ($i, $j) = (0, 0); $i < 1_000_000; $i++) { $j++ if ($i % 3) eq 2; } }, '==' => sub { for (my ($i, $j) = (0, 0); $i < 1_000_000; $i++) { $j++ if ($i % 3) == 2; } }, }); __END__ Benchmark: timing 10 iterations of ==, eq... ==: 28 wallclock secs (27.91 usr + 0.00 sys = 27.91 CPU) @ 0 +.36/s (n=10) eq: 36 wallclock secs (36.16 usr + 0.01 sys = 36.17 CPU) @ 0 +.28/s (n=10) s/iter eq == eq 3.62 -- -23% == 2.79 30% --
The test was run on my Powerbook G3 with Perl v5.8.0 built for powerpc-linux-thread-multi.

I agree we shouldn't program for speed only, but here speed and good form comes from the same expression. Also you may note how my first post in this thread started out with "Also": it wasn't meant to be a comprehensive response to c's problem, but instead my 2 cents to what already said.


$|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g


In reply to Re: Re: Re: eq vs. == by giulienk
in thread eq vs. == by c

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!
  • 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, 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
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (10)
    As of 2014-09-30 13:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (370 votes), past polls