speed and optimisation

D

David

HI all:

I am write a programme has lots exp() (scientific calculation). It seems
that the function in math.h are of double precision.
When my declare data set as float type... it is even slower than declared as
double -- is this probably due to the extra operation needed to covert
double to float?

Will Inter C++ compiler generates code quicker than MS Visual C++ 6 comipler
if I am using an intel processor? (Or any other faster compilers around?)
The programme is mostly float point operations but hasnt utilised MMX,
SSE(n) instructions.....

Thanks

David
 
P

Phlip

David said:
I am write a programme has lots exp() (scientific calculation). It seems
that the function in math.h are of double precision.
When my declare data set as float type... it is even slower than declared
as double -- is this probably due to the extra operation needed to covert
double to float?

At an [off-topic] guess, it's because your CPU has an FPU that offloads all
math as doubles. These critters tend to optimize for the pessimistic cases,
which are doubles. So to run trivial cases, they convert floats to doubles,
process, and convert back.

By this reckoning, you are abusing your hardware. In general, always use
doubles unless profiling reveals a real reason to use floats. Don't guess
floats are faster just because they have "less precision". And regardless
whether C++ processes floats as floats (it usually does), the hardware might
just do it for you...
Will Inter C++ compiler generates code quicker than MS Visual C++ 6
comipler if I am using an intel processor? (Or any other faster compilers
around?)
The programme is mostly float point operations but hasnt utilised MMX,
SSE(n) instructions.....

This question is on-topic for forums that discuss those compilers. If I took
a guess here (beyond general rules of thumb), others here could not review
my post and add details. So always post to the correct newsgroup, for best
results!

(And the rumor is Intel's compilers always produce the fastest code.)

New question: Are you indulging in "Premature Optimization"? Google for that
to make sure. Otherwise, carry on!
 
R

Rolf Magnus

David said:
HI all:

I am write a programme has lots exp() (scientific calculation). It seems
that the function in math.h are of double precision.

And overloaded for float and long double.
When my declare data set as float type... it is even slower than declared
as double

That's pretty much normal in many cases. What reason do you have to use
float instead of double?
-- is this probably due to the extra operation needed to covert double to
float?

On typical desktop systems, the calculations are internally done at higher
precision anyway, and the result has to be converted down afterwards.
Will Inter C++ compiler generates code quicker than MS Visual C++ 6
comipler if I am using an intel processor?

Visual C++ 6 is very outdated an not really the most standard compliant
compiler, and it will probably miss quite a lot of optimization potential
on newer Processors that have been produced after that compiler was
released. Get a more recent one.
 
V

Victor Bazarov

David said:
I am write a programme has lots exp() (scientific calculation). It
seems that the function in math.h are of double precision.
When my declare data set as float type... it is even slower than
declared as double -- is this probably due to the extra operation
needed to covert double to float?
Yes.

Will Inter C++ compiler generates code quicker than MS Visual C++ 6
comipler if I am using an intel processor?

If you mean "Intel C/C++ compiler", then the answer is "yes, usually".
But do upgrade to Visual C++ 2005 Express, it's faster (not as fast as
Intel, but still). Also, keep in mind that the faster you want your
code to be the more time the compiler will spend compiling and optimizing
it.
(Or any other faster
compilers around?) The programme is mostly float point operations but
hasnt utilised MMX, SSE(n) instructions.....

If you search the web for "C++ performance" or "how to optimize" or some
such, you will find that you need to use tools to tell you where the
bottlenecks of your program are. Those tools are called "profilers".

Try 'LTProf' for size, it's free. If you find it too weak, spring for
VTune or AQTime. If you intend to work on your programs' performance,
a good commercial tool is infinitely better than guessing and much better
than rolling your own.

V
 
C

Claudio A. Andreoni

David said:
Will Inter C++ compiler generates code quicker than MS Visual C++ 6
comipler if I am using an intel processor? (Or any other faster compilers
around?) The programme is mostly float point operations but hasnt utilised
MMX, SSE(n) instructions.....

First of all, ensure yourself that your app will run always on processors
that support these extensions... if you compile with them, you cannot run
on all the processors.

As these extensions aren't so common, a lot of compilers won't use them by
default or even don't support them at all.
I am writing a programm that has lots of calls exp() (scientific
calculation).
If you perform a lot of math, the trouble could lay in the C++ library you
use for performing them. A better one will perform faster, so you could try
to change to the math library before changing compiler... search the web
for one...

Just a precisation:
MMX (available since Pentium II and K6) extensions are meant to performed
packed calculation on integers, that means performing the same operation on
a set of different numbers...
I don't think they could help you, if ya do operations on the same values

SSE 1,2,3 (available on Pentium III, IV, Xeon / K6-III, Athlon, Athlon XP)
do the same on floating point numbers. As above, it performs one operation
to more than one float point (float at processor level means mainly C++
'double') in one cycle, so it is useful only if you have to add/sub/mul/div
a lot of different doubles at a time.

Maybe a math library compiled with these extension could help...

Anyway the Intel compiler is told to be the best commercial one (consider
GCC instead, if you prefer open source) and will certainly help speed up
your applications (if you use Intel processors)

Best wishes,
Claudio A.
 
D

Daniel T.

"David said:
HI all:

I am write a programme has lots exp() (scientific calculation). It seems
that the function in math.h are of double precision.
When my declare data set as float type... it is even slower than declared as
double -- is this probably due to the extra operation needed to covert
double to float?

As I understand it. 'double' is supposed to be the optimum size for the
system being compiled to. The size that is native to the FPU. Use double
unless there is a specific reason to use float or long double.
 

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
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top