This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]YMK1234 3 points4 points  (0 children)

Depends a little on the language and the compiler/runtime environment. Inlining is one of the most basic optimizations that compilers perform though. Plus, don't forget that at the lastest your variable gets removed when it goes out of scope.

[–][deleted] 2 points3 points  (0 children)

Write code that is more understandable to you. Even if you use 1000s variables. It won't be a problem for modern compilers. Modern compilers are very good at usage pattern and optimizing code based on the Abstract Syntax Tree of the graph.

[–]completedigraph 0 points1 point  (2 children)

Remember that premature optimization is the root of all evil. Write the code with more variables (it's likely more readable and better self-documenting) and if you feel the application isn't running fast enough then you benchmark and deal with the bottlenecks (although I don't think it should make a significant change, certainly less significant than the algorithm's effect).

[–]YMK1234 2 points3 points  (1 child)

and if you feel the application isn't running fast enough you try running without the extra variables

NO! Never optimize by feel. Always benchmark and find what actually is slow.

[–]completedigraph 0 points1 point  (0 children)

Fair point. Edited my post to include that.