auto abc = 5566;
As far as I know, compiler knows abc
is int
at compile time so it will not affect runtime performance.
However, does it makes compile time longer??
Thanks in advance.
auto
is one character longer than int
, so the lexer definitely has to do more work.
On the other hand, the compiler no longer has to check that the user provided an appropriate type, so my best guess is that auto
will be slightly faster.
In the end, you should probably not decide between type inference and explicit typing based on performance considerations. Intent and clarity should be the deciding factors.
It may, or it may not, it depends on the compiler. Certainly the performance of this is not something mandated by the standard.
Since the lexical analyser knows the type of 5566
anyway, it's likely to be largely irrelevant.
You'd be better off worrying about more "macro" issues like algorithm and data structure selection. You'll almost certainly get a better return on investment than worry about whether auto type selection is faster or not.
Use of auto
in creating variables is not so much about performance as it is about making your life easier as a coder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With