Let's say I have a very long method which basically creates a responsive and resizable layout for a user interface by using a few fixed values and a few variable ones taken from an element's coordinates and width/height sizes. To obtain the desired layout, my code needs to perform basic but repetitive math operations (additions, subtractions, multiplications and divisions) to get every element's coordinates and size.

My code is written in Objective-C.

Let's also say that I want my code to be extremely fast, because it will run on low-performance devices, such as mobile devices.

Since I want to get high performance, does making a very precise declaration for the variable have a performance impact? For example, the compiler will know if the value is a const or unsigned, and optimize the code right along.

For example, which of these cases is faster than the others?

  1. const unsigned int kInteger = 20;
  2. const int kInteger = 20;
  3. int integer = 20;
  4. unsigned int integer = 20;

In other words, does helping the compiler, really have a performance impact? Or is this just a waste of time since it's all just micro-optimization?


1 Answer 1


Can I suggest you not look at performance this way?

You're thinking about it before writing the code.

Instead, write the code, get it running, and then find out what the real performance issues are. The chance that you've guessed correctly ahead of time what they are is very small.

Here's an example of how to do it.

Now, after you've done this, and not before, you will start to recognize the kinds of things that cause performance issues, and avoid them in your subsequent coding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.