Performing a good benchmark is hard. It looks simple, but many times I've seen benchmarks posted on perlmonks which were utterly useless, as they weren't testing what they thought they were testings. Furthermore, the vast majority of the people writing a benchmark run the benchmark on a single data set. Noone seems to have a problem coming up with alternative code fragments to test, but to actually vary the size of the data set is much rarer.

Also, your advice of "Just test both solutions, use whichever is faster, then optimize that one" is just plain wrong. There's no point in benchmarking unoptimized code, and then decide which solution to toss away. Suppose you have algorithms A and B, benchmark them, and find A to be twice as fast as B. Now you toss away B, and optimize A. Suppose after optimization, A runs three times as fast; that is, 6 times as fast as the unoptimized B. But maybe it was possible to optimize B such that it runs 10 times as fast, making it faster than the optimized A. You wouldn't know, you've already (and too early) decided to go for algorithm A.

You should benchmark *optimized* code. And you should run it with a large range of data set sizes.

Abigail


In reply to Re: Need help on performance question by Abigail-II
in thread Need help on performance question by j.goor

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.
  • 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:
    & &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.