Is accessing const variables faster than non-const variable? I’m wondering if it is worth using const more as a step in optimizing a program.
Is accessing const variables faster than non- const variable? I’m wondering if it 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.
The answer to your question is maybe.
As Bjorn pointed out this question can only be answered by careful benchmarking because there are too many architecture specific reasons why the answer could be yes or no.
Here is a StackOverflow reference on benchmarking:
If you are working on a project where speed matters then the only way to really know what the compiler is doing and how it impacts speed is to read the generated assembly and perform careful benchmarking. Theorizing about what the compiler could do isn’t productive. If you are working on an embedded system an oscilloscope is a great way to time things, on machines with more resources a high resolution timer provided by the OS is useful.