Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Some quick thoughts:

Firstly, its always good to see if your results stay the same if you permute the test conditions a bit. Make sure you try different numbers for a and b - perhaps graph how these methods change over different ranges.

More interestingly, does changing the order you run your benchmarks change anything? (e.g. does the first run of a memory-hungry implementation cause the process to grab lots of VM from the OS which is then re-used more quickly by the malloc in later runs? Conversely does heap fragmentation slow down memory management for later runs?)

Another thing to keep in mind is that the perl 'interpreter' actually runs an optimisation pass. When you put together simple sample code, things might be trivially optimised away which might not be in your production code.

Lastly, I'm not sure all your examples are comparing like with like. I'd be very wary (vary wery?) about using microbenchmarks to suggest which approach is best for a production app. (For example, what you are attempting is a classic memory/speed trafeoff. Your test and production environments may vary widely in available memory under load.)

Sorry if this is teaching grandma how to suck eggs, but you are better off timing/benching a real app rather than sample code.

PS. Array lookup is a cheap operation in most languages. It is a straight memory reference. The cost is in consuming memory and how that affects end system performance.

Lastly, if you are really caching multiplications then have you considered bit twiddling? :-)


In reply to Re: Fundamental Benchmarks by jbert
in thread Fundamental Benchmarks by Lexicon

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 exploiting the Monastery: (8)
    As of 2014-08-20 21:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (124 votes), past polls