platform independent table access performance

C

Case -

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?

Thanks,

Kees
 
D

Dave Vandervies

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
 
K

Kevin D. Quitt

Further, if you're talking about an embedded environment, the pre-filled
table might be in ROM, while the run-time-calculated version will be in
RAM. Which is faster to access on the specific platform? Probably the
RAM. Will you be spending enough time in the sin() routine to justify the
initialization time?

And if you declare the array as non-const, then it will be in RAM, even if
it's pre-initialized (unless your compiler is beyond smart and getting
close to omniscient).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top