Archived

This topic is now archived and is closed to further replies.

Integer calculations faster than float calcs ??

This topic is 5754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Are calculations (in vc++ 6) with integers faster than calculations with floats. In my terrain demo (which uses a lot of sinus, divide and multiply operations) I only use floats. But I saw some code of another demo which only used integers. Is this really faster? How much would this differ? I can make my terrain size very large, so it won''t matter if you use float or integers. Thanks, Edo

Share this post


Link to post
Share on other sites
floats are faster then ints on modern cpus provided you dont cast to int very often if at all. also make sure you ONLY use floats and not doubles. use sinf(), cosf(), etc. instead of the double versions of the functions. since the floating point versions are faster (due to less percision). try to convert divides to mulitplys where possible. try to limit the number of times you call sinf() since sinus us a slow function to calculate. in fact search this board for some faster implementations then the standard one with msvc++ 6.0 (the topic was something like "fast trig functions").

the only true way to see if there will be a difference is to actually test both methods.

Share this post


Link to post
Share on other sites
it depends on the processor and the load (the fastest is actually if you can get your ints and floats to run in parallel, since they are generally in separate execution units). generally standard float math functions are now about the same speed as int instructions. trancendental functions and sqrt are very slow still ( relatively speaking that is -- ~150 cycles on a 2 gHz processor is less than 100 nano seconds, which is a lot faster than my old 286 could do an INC instruction). divide is usually slightly slower than multiply. Assuming you can read assembly (and really even if you can''t) you can get the clock cycle per instruction figures from AMD or intel.

Share this post


Link to post
Share on other sites
Using the type float instead of double is just a hint that you only need a certain degree of precision, but the CPU internally handles all floating-point types identically. At least, that''s what I read somewhere.

Share this post


Link to post
Share on other sites
quote:
Original post by fallenang3l
Integers are always faster than floating-point numbers. Don''t know how much faster, but when you have lotsa loops and calculations it definitely adds up to be significant.


This is highly processor dependent. Your statement is patently false on any massively parallel processor, such as a Cray (which I actually got 5 minutes of CPU time on one quarter; only ended up using about 45 seconds). Float and double ops were slower than integer ops on the 8086, and I haven''t kept up with things since then. I have worked on processors that don''t offer floating point ops, and it requires a whole different approach to use fixed-point calculations, so I wouldn''t suggest going that way unless you had a good reason.

Share this post


Link to post
Share on other sites