Is there a performance difference between i++ and ++i if the resulting value is not used?
Is there a performance difference between i++ and ++i if the resulting value is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Executive summary: No.
i++could potentially be slower than++i, since the old value ofimight need to be saved for later use, but in practice all modern compilers will optimize this away.We can demonstrate this by looking at the code for this function, both with
++iandi++.The files are the same, except for
++iandi++:We’ll compile them, and also get the generated assembler:
And we can see that both the generated object and assembler files are the same.