In article <42**********************@dreader2.news.tiscali.nl >,
Case - <no@no.no> wrote:
Dear people,
I have a scaled up short sin(short) function which uses
a lookup table. The code will be used on different
platforms (from mobile phone to desktop computer).
(Yes, I know sizeof short can differ.)
Here my slightly OT question: Is there anything to
say about execution speed differences between using
an initialised static const short array, or an array
which I fill during start-up?
There is: "It depends".
On a desktop computer, the startup cost to compute the lookup table is
likely to not be noticeably different than the time it would take to read
in a precomputed table from wherever it's stored, and once the values are
there looking them up is almost definitely going to be done the same way
(and therefore at the same speed).
On smaller platforms, the implementation may be able to put one of them
somewhere where it can get at it faster than the other. Whether this
is the case, and which one is faster, will depend on the platform.
But, most likely, the standard rules for optimization apply here:
(1) Don't do it
(2) (for experts only) Don't do it yet
On a slow processor, you're probably looking at the difference between
"fast" and "fast"; on a fast processor, you're almost definitely looking
at the difference between "incredibly fast" and "incredibly fast".
dave
--
Dave Vandervies
dj******@csclub.uwaterloo.ca
My original comment was designed to prevent this discussion arising.
I should have known better.
--CBFalconer in comp.lang.c