Damian
Damian

Reputation: 5561

gcc: why casts of literals are not optimized?

I'm coding a game for iphone in c, and after running into some performance problems I decided to use instruments to check where the bottlenecks are, and I found out that casts of literals are not being optimized.

For example:

if(x == (float)3) {....}

runs faster if I write it like this:

if(x == 3.0f) {....}

Why isn't that optimized by the compiler?
I'm using gcc in release mode.

Upvotes: 3

Views: 142

Answers (1)

Damian
Damian

Reputation: 5561

Soooorry, as the comments said, I looked at the object code and is the same.
Xcode instruments gives you line by line the amount of time spent, I see it's not 100% reliable.

Upvotes: 1

Related Questions