5 ms·
I think the range of compilation times for C and different styles of C++ is so huge that this question cannot be answered without going into a lot of details ab
by flohofwoe 7y ago
I think the range of compilation times for C and different styles of C++ is so huge that this question cannot be answered without going into a lot of details about how the C or C++ project is structured.
You can compile hundreds-of-thousands of lines of "user-side" C++ code in a few seconds, or in a few hours. The range is much smaller in most C projects, but can also differ by orders of magnitude.
In short, splitting a C++ project into many small source files (e.g. "one file per class") combined with using a lot of C++ stdlib headers in each small source file is the worst case for a C++ project because of all the complex stdlib template code that needs to be compiled over and over again. This can increase the "under-the-hood" line count by several hundred times (in Google Chrome, the amount of "project C++ code" is only 0.125% of all the code the compiler needs to compile when rebuilding the project because of included headers):
https://randomascii.wordpress.com/2020/03/30/big-project-build-times-chromium/ https://randomascii.wordpress.com/2020/03/30/big-project-bui...
AFAIK Rust solves part of this problem with its module system, but the compilation time problems lurk elsewhere.
Here's an interesting webpage which looks at compilation time of C++ stdlib headers and some popular 3rd-party libs:
https://artificial-mind.net/projects/compile-health/ https://artificial-mind.net/projects/compile-health/
- ashtonkem 7y agoIF I understand correctly, the borrow checker comes with some pretty severe compilation costs, since it requires a pretty wide level of code analysis, and might be single threaded.
- steveklabnik 7y agoNot generally, no. Or rather, there are other things that are a much bigger cost.
- aw1621107 7y agoRust's type system takes up a surprisingly small portion of compilation time. See the comment rooted at [0] for some discussion. tl;dr: Profiling and tests show that codegen and LLVM work takes up the lion's share of compilation time. The borrow checker itself isn't that expensive in the grand scheme of things, and languages like OCaml show that it's very feasible to have a complex type system that compiles quickly. [0]: https://news.ycombinator.com/item?id=22935795 https://news.ycombinator.com/item?id=22935795