Good point Beer Hunter. I will recheck the book I saw it in and post what it states. Also, did you try it under MSVC?
-----------------------------
"There are ones that say they can and there are those who actually do."
"...u can not learn programming in a class, you have to learn it on your own."
hi, i was wondering if you're program contains lots of "if..else", does it in anyway
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
A _simple_ ''if'' statement uses on average 1.5 assembly language instructions. Now, your computer can perform millions of assembly language instructions per second (depending on the processor maybe billions) An ''if'' statement is
not going to affect performance a great deal at all.
''Your theory of a donut shaped universe is intriguing Homer'' - Stephen Hawking
not going to affect performance a great deal at all.
''Your theory of a donut shaped universe is intriguing Homer'' - Stephen Hawking
The problem with ''if'' statements, is that they do not only produce 2 assembly opcodes. They mess with branch prediction, and this can kill you, depending on what you do.
I would avoid *huge* if/else trees. Besides of the performance hit, it''s also very ugly and points to a design flaw in your code. A good way to replace if/else trees that are based on comparing a simple value are function pointer tables.
So, instead of writing
if( v==1 ) DrawSphere(); else
if( v==2 ) DrawCylinder(); else
if( v==3 ) DrawTeapot(); else
if( v==4 ) DrawStuff(); else
...
you do
(*FunctionPointerTable[v])();
So much easier and faster.
I would avoid *huge* if/else trees. Besides of the performance hit, it''s also very ugly and points to a design flaw in your code. A good way to replace if/else trees that are based on comparing a simple value are function pointer tables.
So, instead of writing
if( v==1 ) DrawSphere(); else
if( v==2 ) DrawCylinder(); else
if( v==3 ) DrawTeapot(); else
if( v==4 ) DrawStuff(); else
...
you do
(*FunctionPointerTable[v])();
So much easier and faster.
function ptrs are not always faster, but are much cleaner. plus switch statments get broken into a jmp table anyway, so the speed difference is not too great if any at all, especially if your not doing much in the case (ie just making an assignment). functions require pushing stuff on the stack and other crap that could reduce speed. stay away from fuction ptrs unless you are actaually going to have decent functions (ie like drawing stuff).
quote: Original post by mickey
whoa what was that..
Its called Assembly language. Raw code, if you will All the instructions (mostly 3 leter words) you see are directly executed one-by-one, simutaneusly incresing the SI register (i think its called SI, not shure). The CPU does the instruction always pointed to the SI register (points to the code execution memory offset).
[ my engine ][ my game ][ my email ]
SPAM
Rate me up.
Beer: only in 32-bit systems, I believe. Otherwise it has a different name. Either way, it''s the instruction pointer.
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[if you have a link proposal, email me.]
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
hey guys thanks for all the feedbacks, i didn''t knew my thread will take this long!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
a person:
I wouldn''t use function pointers for easy case statements, if it''s only an assignment, a lookup table could be used after all. But for more complex stuff, they are very useful. Esp. when replacing huge if/else or switch trees, eg. for commandline interpreters (shells), and such things.
In 32 bits: EIP
In 16bits: IP, (implicit) segment prefix is cs
Just as AX, EAX, SP, ESP, etc.
I wouldn''t use function pointers for easy case statements, if it''s only an assignment, a lookup table could be used after all. But for more complex stuff, they are very useful. Esp. when replacing huge if/else or switch trees, eg. for commandline interpreters (shells), and such things.
quote:
Beer: only in 32-bit systems, I believe. Otherwise it has a different name. Either way, it''s the instruction pointer.
In 32 bits: EIP
In 16bits: IP, (implicit) segment prefix is cs
Just as AX, EAX, SP, ESP, etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement