Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,787 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
operators speed considerations #324042
05/19/10 08:03
05/19/10 08:03
Joined: Feb 2010
Posts: 68
mireazma Offline OP
Junior Member
mireazma  Offline OP
Junior Member

Joined: Feb 2010
Posts: 68
Hello.
It's extremely important, at least for me, to take into account the speed of execution of every statement/operator/construct in the language I use, so when it comes about using one of several approaches, to pick the fastest one.
One might argue that the difference between checking with an if statement and simply managing the condition mathematically within the += operator doesn't have a visible performance impact. Or using abs(value) instead of the if check.
However, bit by bit, at a given point, there will accumulate a difference if one doesn't pay attention to this.
This is a kind of apology for what I'm going to ask laugh
As Lite-C is based on C (and C++ ?) Are the performance ratings for the Lite-C constructs (I hope I'm using the right word) the same as for C/C++? And I would deeply appreciate if somebody would show me where I could find a table with them either for Lite-C or C/C++; something like:
+, - 1 CPU cycle
*, / 1.1 CPU cycles
if 1.2 CPU cycles
for() 2.5 CPU cycles
abs() 2 CPU cycles
etc.
At least to state if they're of low/medium/high speed like in the A7 manual.


ERROR in communism.cpp, line 0:
#include<god.h>
was fatally missed.
Re: operators speed considerations [Re: mireazma] #324073
05/19/10 13:11
05/19/10 13:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Lite-C is not based on C or C++, it provides a full ANSI C compiler, so every ANSI C code will compile on the GS compiler as well. But Lite-C offers additional functionality like the automaticc detection of pointers, which is neither to be found in C nor in C++.

I can't give you any information on cpu cycles a certain instruction uses. But you already made a pretty good guess when writing them down. Fastest instructions are bit shifting and binary operators like <<, >>, |, & etc. The arithmetical operators like +, -, / and * will be slower but even very very fast. The exectuion speed of this also depends on the operands you use with them. The if condition will be again one step slower. The for loop depends on the number of iterations, the use of a already defined variable for iterating, the content of the body of the loop and the like. So you can't give a general rule for that. The most costly thing is of course calling a function like abs.

To be not misunderstood: all of the above is lightning fast. In terms of the manual they are all very very very fast. I do not recommend to optimize your code on this level as you write it. One does better to write readable, well organized and documented code.

One of the most important rules for programmers: Don't optimize before it's too slow.


Always learn from history, to be sure you make the same mistakes again...
Re: operators speed considerations [Re: Uhrwerk] #324577
05/21/10 20:08
05/21/10 20:08
Joined: Feb 2010
Posts: 68
mireazma Offline OP
Junior Member
mireazma  Offline OP
Junior Member

Joined: Feb 2010
Posts: 68
Thank you very much. I'm new to programming with C++ and Lite-C. I'm learning from the tutorials. I'll remember your advices.


ERROR in communism.cpp, line 0:
#include<god.h>
was fatally missed.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1