Re: efficiency problem

From: Eric Sosman (eric.sosman_at_sun.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 17:34:25 -0500

Andrew Bullock wrote:
>
> I understand what you're saying about the try/catch, however the "if"
> method seemed to make it slower rather than faster for me (probably
> because it has to to the comparison every cycle, most of which times it
> will be false?)

    Please refer to my recent unseemly diatribe on essentially
the same topic over in comp.lang.java.programmer, in a thread
titled "Performance of null tests?" (Not self-promotion: it's
just that I'm trying to cut down on writing and re-writing the
same diatribe -- bad for the blood pressure.)

    (For extra credit, spot the error in my broadside -- not
in the assumptions, which are intentionally optimistic to the
point of bending over backwards, but in the conclusions I drew
from them. Hint: Spaces are not lines.)

    "It stands to reason" that your option a should be slower,
and when I replicated your experiment (based on an incomplete
description), that's exactly what happened. You're seeing
the opposite -- and I strongly suspect that it has nothing
whatever to do with the `if', but everything to do with some
other part of your code, or with a sloppy time measurement.
Seek elsewhere for the source of your troubles -- but don't
seek harder than the troubles themselves are worth. Remember
that you'll need to realize your 100ms savings 36,000 times
to recoup just one hour spent achieving it ...

-- 
Eric.Sosman@sun.com