Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Floating points are evil!!!!!!!

Author
Message
The Wendigo
23
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 22nd May 2003 10:14
I hear a lot of complaints about peoples programs being too slow. Well, I don't know how many of you guys use a lot of FLOATs but I did a calculation that says that integers are almost 3 times faster than floating points! Generally this wouldn't be noticeable, but if you are using nested loops from 1 to 512 each (used a lot for texturing) then you are calculating 262000 times per game loop. I'd advise against using floats if you can get out of it.

Avoid: G# = G# * 5
Use: G = G * 5

I know that floats sometimes can't always be avoided, but try to if you can.

This has been a public service announcement :-s
Current Projects: mini BSP maker 50%, Height Mapper with many features 75%, FPS/RTT Nameless at the moment 15%
Witch Bomber
23
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 22nd May 2003 11:36
Thanks for just repeating 25% of the Software Development unit of Higher Computing (as if I haven't heard enough of it by now). My exam is in 4 hours.

Don't visit the Mad Matt Games Website
The Wendigo
23
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 23rd May 2003 00:13
Well, out where I live, they don't tell you any of this type of crap. Nobody has said crap about it anywhere in my classes and I have a friend that goes somewhere else that is worse off than i am. I'm basically saying this for the newbies so maybe I should have this moved to the NewB section.

Current Projects: mini BSP maker 50%, Height Mapper with many features 75%, FPS/RTT Nameless at the moment 15%
haggisman
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 23rd May 2003 00:27
TBH i doubt changing from the use of floats to integers will make make much difference in real world applications...

Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 23rd May 2003 07:30
Depends on what you're doing as to which is faster.



Many commands operate at best efficiency when you pass them real numbers (floats) instead of integers although basic mathematic operations are always faster as an integer. ie. A+B is faster as an integer.

DB commands however are expecting real numbers and optimised for use on the maths co-processor. Giving them integers will meen the variable has to be moved from the cpu stack to the fpu stack which will loose you some cpu cycles.

In short, try to use the variable type associated with the command, rather than forcing a conversion.

Pneumatic Dryll
Witch Bomber
23
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 24th May 2003 13:44 Edited at: 24th May 2003 13:45
Thanks for the tip PD. Could you give me more information? When I do my AH computing project I should probably spend a few weeks optimising efficiency so if I knew just how much processor time is wasted on a "position object integer,integer,integer" command I could do some calculations on which is better. The project is 50% of the grade so if I spend ages on stuff like that I walk into the exam hall and I've already passed, and 50% in the exam will give me an A!

Don't visit the Mad Matt Games Website
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 24th May 2003 17:16
Well if your holding positioning information and in your program your position variable is mostly used in basic mathematical operations such as:

position=position+movement
position=position-knockBackEffect

Then you are faster as an integer, but if you are using the variable mostly with object handling commands such as:

move object player,movement#
move object player,-knockBackEffect#

You are probably better off using real numbers.

Sadly, the only real way to know for sure is to speed test each alternative.

Ultimately optimisation of your variable types will only leed to a minor fps change and is really only about eaking out every last ounce of performance.

Technique and methodology count for a lot more than variable types in the final performance of your program, such as that building that is only visible when you are at that point in the map ... is it drawn every frame?

Pneumatic Dryll
Witch Bomber
23
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 24th May 2003 19:12
Yeah I know data types aren't particularly important but in an Advanced Higher an extra 1% is worth the computer's weight in gold, and markers are really picky about efficiency.

Don't visit the Mad Matt Games Website
ozak
23
Years of Service
User Offline
Joined: 22nd May 2003
Location: Denmark
Posted: 26th May 2003 12:04
Well, not using floats for realtime 3D would be very bad. Besides, floating points operations are fast now. The only reason to use fixed point math is if you're on a slow processor, without a floating point unit or memory/bandwidth limited (hardly the case today, ok there some situations, but they are rare .
What can be slow however, is the conversion between int and float so try to avoid this in core loops that muse be as fast as possible.

Regards

Ozak

Witch Bomber
23
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 26th May 2003 20:09
The point is not practical, I know the computer will be able to handle it no matter what the data type, but the less processor time and RAM capacity wasted, the more marks I get (whether it affects the speed of the program or not), especially if I do an investigation into stuff like int to float conversions.

Don't visit the Mad Matt Games Website
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th May 2003 02:15
Ok, here's the info I'm aware of.

For modern processors (PIII and above, K6-2 and above) floating point is *almost* as fast as integer maths, in pure machine code...

But... (you knew that there'd be a but didn't you? )

1) The stack for floating point operations is only 8 deep, where integer maths is effectively only limited by the memory model of you machine (2 GB for win9X and 3 GB for winNT/2K/XP).
2) DBPro does *not* do pure machine code for floating point.

Having studied the code generated by DBPro, and its plugin libraries (that's where the interface library comes from!), I know that *currently* most (if not all) floating point operations are handled by library calls. That obviously gives you an overhead - not a large one, but for highly intensive maths, it is detectable.

This does not mean that you should stay away from floating point maths though - the conversion between floating point and integer maths is probably the biggest speed killer you'll come across.

As PD said, the only way to really find out is on a case-by-case basis, using trial-and-error.

Login to post a reply

Server time is: 2026-07-11 11:06:56
Your offset time is: 2026-07-11 11:06:56