http://qs1969.pair.com?node_id=681156


in reply to CPU cycles DO NOT MATTER!

My thoughts on this mostly echo Kyle's, but there is another point to bring up: significance.

Benchmarks with tiny differences often aren't even significant. That is to say, that 3 millionths of a second you gain in your example might not just be tiny, but not actually reliably exist. I'm searching now for, but cannot find, an old node here that showed that trivial and seemingly unrelated changes to the source bumped the results around by a few percent.

As far as the original point goes, CPU cycles almost never matter. But there do exist cases where swapping one algorithm for another can offer you a big speed difference in a place where it actually matters.

I think my own optimization decision making gets summed up pretty well by the following:

  1. Is it slow?
  2. Should I care that it is slow?
  3. Is there an obvious fix? (I.e. am I accidentally iterating over a whole data set when I could drop out on the first success or failure, etc.)
  4. Will new, faster hardware be in place by the time I finish this thing, anyway?
  5. Can I buy the problem away by throwing hardware at it?
  6. Okay, guess it is time to optimize.

Replies are listed 'Best First'.
Re^2: CPU cycles DO NOT MATTER!
by kyle (Abbot) on Apr 17, 2008 at 16:22 UTC

    I'm searching now for, but cannot find, an old node here that showed that trivial and seemingly unrelated changes to the source bumped the results around by a few percent.

    You may be looking for No More Meaningless Benchmarks! (an excellent node for all users of Benchmark).

      That is indeed the node, thank you very much.

Re^2: CPU cycles DO NOT MATTER!
by radiantmatrix (Parson) on Apr 21, 2008 at 16:20 UTC

    0. Does it work?

    My take on "premature optimization is the root of all evil" is simple: first, make sure everything works correctly (e.g. passes all tests).

    Then, and only then, should you look at the remainder of that list.

    Also, between 3 and 4, a good question is "will any fix make it fast enough to be worth my time to implement?"

    <radiant.matrix>
    Ramblings and references
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet