slight performance suggestion
+2
sio2interactive
freebird373
6 posters
slight performance suggestion
Wherever you use float division you could replace it with float multiplication (faster).
for example:
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) / 100.0f;
could be
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) * 0.01f;
Not much of a factor, but it all adds up .
for example:
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) / 100.0f;
could be
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) * 0.01f;
Not much of a factor, but it all adds up .
freebird373- Posts : 10
Join date : 2008-11-21
Re: slight performance suggestion
you are absolutely right... I try to do that as much as I could within SIO2, but for the tutorials well that's just for demonstration purpose so... but in any case if you find some within the SIO2 code lemme know!
Cheers,
Cheers,
Re: slight performance suggestion
Can I ask why that is faster? Ans why --i is faster than i--. Any reason? Just curious
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
Re: slight performance suggestion
Multiplication is always faster than division, for CPU optimization reasons. I'm sure google knows exactly why.
So, instead of dividing by ten, multiply by 0.1, for the same result but faster!
-j
So, instead of dividing by ten, multiply by 0.1, for the same result but faster!
-j
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: slight performance suggestion
Thanks! That make sens, but --i is faster than i--, that doesn't make sens to me
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
division
oioioi wrote:Can I ask why that is faster? Ans why --i is faster than i--. Any reason? Just curious
Division is extremely slow in most CPUs, it's a matter of how the circuitry is constructed. Multiplication is always much faster.
(Some CPUs don't even offer hardware support for division, it is emulated in software!)
aheirich- Posts : 11
Join date : 2009-02-25
Re: slight performance suggestion
freebird373 wrote:Wherever you use float division you could replace it with float multiplication (faster).
for example:
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) / 100.0f;
could be
_SIO2particle->speed = (float)sio2Randomui( (unsigned int)MAX_SPEED ) * 0.01f;
Not much of a factor, but it all adds up .
A few comments regarding this:
1) most good compilers like GCC, which is used for iPhone development, automatically "optimize" division by a constant into multiplication by the inverse constant. I haven't checked this on the iPhone SDK, but I would be shocked if it didn't do this.
2) Multiplication and Division can be made equally as fast on modern hardware. It all depends on the architecture. For iPhone, division is slower than multiplication.
3) The original form is preferable for readability.
SPQR
spqrusa- Posts : 1
Join date : 2009-03-16
Re: slight performance suggestion
Someone should do some time tests ;.
This article is bit outdated but suggests not to use division at all.
http://msdn.microsoft.com/en-us/library/ms839365.aspx
This article is bit outdated but suggests not to use division at all.
http://msdn.microsoft.com/en-us/library/ms839365.aspx
freebird373- Posts : 10
Join date : 2008-11-21
Re: slight performance suggestion
My results from a little test on the 2G ipod touch.
temp = 525.0 / 3.0f;
vs.
temp = 525.0 * 0.333333334f;
One iteration
div: 0.0000099999999748 secs
mult: 0.0000059999999849 secs
10,000 iterations
div: 0.0001499999996213 secs
mult: 0.0001259999996819 secs
eh, NOT much of a difference as expected.
temp = 525.0 / 3.0f;
vs.
temp = 525.0 * 0.333333334f;
One iteration
div: 0.0000099999999748 secs
mult: 0.0000059999999849 secs
10,000 iterations
div: 0.0001499999996213 secs
mult: 0.0001259999996819 secs
eh, NOT much of a difference as expected.
Last edited by freebird373 on Tue Mar 17, 2009 1:41 am; edited 1 time in total
freebird373- Posts : 10
Join date : 2008-11-21
Re: slight performance suggestion
hummmmmm really interesting... more of theses type of benchmark would be great that can help us all to optimize our code better...
Cheers and tks!,
Cheers and tks!,
Similar topics
» Suggestion for LOD
» tutorial suggestion
» Supurb. Tutorial suggestion...
» Sample/Tutorial Suggestion
» tutorial suggestion
» Supurb. Tutorial suggestion...
» Sample/Tutorial Suggestion
Permissions in this forum:
You cannot reply to topics in this forum