Skip to main content
gamedev.net
🔒 Locked

Compairson optimization?

Started by glaskows Sep 8, 2003 at 6:14 PM 5 replies 400+ views
Original Post
glaskows
glaskows
if i do this lots of times: which is faster? are they the same? if((A+B)<0) ... or if(A<-B) ...
krez
krez
what about:

if(!(A+B))
{
// all the stuff that you have after each if
};
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Raloth
Raloth
Better question: Does it matter? This is a micro-optimization that the compiler will most likely take care of for you.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
PHRICTION
PHRICTION
I would go with "if((A+B)<0)", just because it''s easier to read. Having your program run a couple microseconds faster is in most cases second to having clear and simple code, because it will reduce debugging time in the long run.
PHRICTION
PHRICTION
You don''t have to be so picky. First of all, I said "in most cases," and most of your code probably isn''t in your innner loop (well, no in my project anyway).

And when I said a couple of microseconds, I didn''t mean to imply that "if((A+B)<0)" would take a couple of microseconds more than "if(A<-B)." I was ''speaking'' in generic terms.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.