tags:

views:

93

answers:

1

Hey All,

I was wondering which of the following is less expensive on memory? I noticed you can leave out the *M_PI portion and it still will work fine. Does this mean if saves some calculations as well or does it matter?

Example:

CGAffineTransformMakeRotation(0.5*M_PI);

Or other example:

CGAffineTransformMakeRotation(0.7); for example.

I would think the last example is more efficient because it doesn't have to multiply by PI or am I wrong in assuming that?

Over all I don't think either one is over powering and a big memory suck I just was curious about what is happening under the hood.

+2  A: 

Neither is a 'memory suck' since both involve the same amount of allocated memory for a CGAffineTransform struct.

Additionally, neither one offers a CPU advantage over the other, since 0.5*M_PI can be calculated at compile time, so is equivalent of writing 0.7 or other constant.

Jason
Yes, I think this is a case of premature optimization. Unless this shows up as a hotspot in your code when testing (which I doubt it would), go with the cleaner, more descriptive implementation.
Brad Larson