FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

slight performance suggestion

+2
sio2interactive
freebird373
6 posters

Go down

slight performance suggestion Empty slight performance suggestion

Post  freebird373 Thu Mar 12, 2009 12:50 am

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 .

freebird373

Posts : 10
Join date : 2008-11-21

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  sio2interactive Thu Mar 12, 2009 1:22 am

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,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  oioioi Thu Mar 12, 2009 8:12 am

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

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  meteors Thu Mar 12, 2009 8:41 am

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
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  oioioi Thu Mar 12, 2009 9:24 am

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

Back to top Go down

slight performance suggestion Empty division

Post  aheirich Thu Mar 12, 2009 12:34 pm

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

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  spqrusa Mon Mar 16, 2009 5:00 pm

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

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  freebird373 Mon Mar 16, 2009 9:56 pm

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

freebird373

Posts : 10
Join date : 2008-11-21

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  freebird373 Mon Mar 16, 2009 10:35 pm

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.


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

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  sio2interactive Mon Mar 16, 2009 11:34 pm

hummmmmm really interesting... more of theses type of benchmark would be great Wink that can help us all to optimize our code better...

Cheers and tks!,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

slight performance suggestion Empty Re: slight performance suggestion

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum