I think you're conflating regular auto use with using it as a return type/argument. The latter is syntactic sugar for declaring a template. It isn't any less "documented" than doing a template<class ReturnType>....
Having the return type name is absolutely better documented. But I guess were splitting hairs because its a hard typed language and lexers can find what it is anyway.
From my discussion with C++ folk, auto is just part of the "modern" way of doing c++. Paired with the -> return type. Perhaps including that -> return type negates this problem? It's still strange to me. Feels more like Rust
This is interesting, but drawing conclusions from only two measurements is not reasonable. Especially so when the time-span measured is in the order of a few ms. For example, the two instances of clang might not be running at the same clock frequency, which could easily explain away the observed difference.
Plus, you could easily generate a very large number of functions, to increase the amount of work the compiler has to do.
So I did just that (N = 10,000), using the function from the article, and used hyperfine to perform the actual benchmarking.
With int
Benchmark 1: clang -o /dev/null test.cpp -c
Time (mean ± σ): 1.243 s ± 0.018 s [User: 1.192 s, System: 0.050 s]
Range (min … max): 1.221 s … 1.284 s 10 runs
With auto
Benchmark 1: clang -o /dev/null test.cpp -c
Time (mean ± σ): 1.291 s ± 0.015 s [User: 1.238 s, System: 0.051 s]
Range (min … max): 1.274 s … 1.320 s 10 runs
So if you have a file with 10'000 simple functions with/without auto, then it increases your compile time by ~4%.
I'd worry more about the readability of auto, than about the compile time cost at that point
technically it doesn't have to (you can always create a .tpp (which is still technically a header, i know, but it isn't a header header)), but i get what you mean
I mean it has to functionally be a header. Could even be a .c file, filename extensions stopped mattering before we even had C++03 and that's saying something!
13 Comments
sukhmel@programming.dev · 11 pts · 348d
LodeMike@lemmy.today · 3 pts · 348d
Why the fuck do people do this to themselves.
Lembot_0004@discuss.online · 5 pts · 348d
LodeMike@lemmy.today · 3 pts · 348d
Nuter one of the main reasons for headers: documentation.
entwine@programming.dev · 2 pts · 348d
I think you're conflating regular auto use with using it as a return type/argument. The latter is syntactic sugar for declaring a template. It isn't any less "documented" than doing a
template<class ReturnType>....LodeMike@lemmy.today · 1 pts · 348d
Having the return type name is absolutely better documented. But I guess were splitting hairs because its a hard typed language and lexers can find what it is anyway.
DapperPenguin@programming.dev · 3 pts · 347d
From my discussion with C++ folk, auto is just part of the "modern" way of doing c++. Paired with the -> return type. Perhaps including that -> return type negates this problem? It's still strange to me. Feels more like Rust
bitcrafter@programming.dev · 2 pts · 347d
One day the use of
autowill grow so extensive that modern Python code will have more type annotations than modern C++ code!6nk06@sh.itjust.works · 1 pts · 317d
Clean code, and compile-time is irrelevant for most projects.
fruitcantfly@programming.dev · 8 pts · 348d
This is interesting, but drawing conclusions from only two measurements is not reasonable. Especially so when the time-span measured is in the order of a few ms. For example, the two instances of
clangmight not be running at the same clock frequency, which could easily explain away the observed difference.Plus, you could easily generate a very large number of functions, to increase the amount of work the compiler has to do. So I did just that (N = 10,000), using the function from the article, and used hyperfine to perform the actual benchmarking.
intautoSo if you have a file with 10'000 simple functions with/without
auto, then it increases your compile time by ~4%.I'd worry more about the readability of
auto, than about the compile time cost at that pointSpeiser0@feddit.org · 2 pts · 348d
If a function body is expensive to parse, isn't it then a complex function body that shouldn't go into the header anyways?
lambalicious@lemmy.sdf.org · 4 pts · 348d
If it's templated / generic, which IIRC is one of the reasons to try and use auto, then it has to go in the header anyway.
bunitor@lemmy.eco.br · 1 pts · 348d
technically it doesn't have to (you can always create a .tpp (which is still technically a header, i know, but it isn't a header header)), but i get what you mean
lambalicious@lemmy.sdf.org · 1 pts · 348d
I mean it has to functionally be a header. Could even be a
.cfile, filename extensions stopped mattering before we even had C++03 and that's saying something!snikta@programming.dev · -5 pts · 347d