Re: Getting rid of "if condition" by some math equation.
Sanny, you should attribute quotes.
Patricia Shanahan wrote:
Have you considered a lookup-table? It would have 65536 elements, but
most of the accesses would probably be concentrated in a few areas, so
it would be quite cache-friendly. You could map to e.g. 1 for "-" and 0
for anything else, then do arithmetic on the lookup result.
Sanny wrote:
Problem Solved. I tried a lookup table and now all if conditions have
been removed.
Now its just a piece of addition. Which quite fast 3-4 times faster
than the if conditions.
I'm curious, Sanny, why you have not answered the several people who asked how
you obtained these speed conclusions. I, for one, was on tenterhooks for the
answers, and only forbore from echoing the question before now because I felt
so sure that after four or five posts of the same question you would actually
deign to answer it. Alas to be so disappointed.
And we're reasonably clued in enough to guess that you ran a benchmark. The
answer needs to be rather white-box: how do you distinguish the time in "if"
evaluation from that in other areas of code? What were the hard numbers for
the loop and unrolled version? What Hotspot warmup protocol did you use? Did
you exclude JVM startup time? 3-4 times faster than what time, exactly?
Microbenchmarks are notoriously unreliable estimators of real-world
performance, especially for Java. Things like running benchmarks under
different load conditions or different threading scenarios over different
numbers of CPUs from a production version are infamous legends in the world of
performance engineering. I for one am deeply dubious of your benchmark
claims, vague as they are and unaccompanied by a detailed description of your
testing rigors, much less actual code.
Please provide the requisite fill for the gaps in our knowledge.
--
Lew