3 ms·
C++ with all optimizations disabled is still slow. g++ takes 2.8 seconds to compile a simple helloworld on my machine - or .14 seconds the second time after cac
by bluGill 8y ago
C++ with all optimizations disabled is still slow. g++ takes 2.8 seconds to compile a simple helloworld on my machine - or .14 seconds the second time after caches are warm... Python2 can build and run helloworld in .028 seconds, or .011 once caches are warm. Of course the C++ hello world runs in .002 seconds once build (caches don't seem to make a difference but that might be because it was still in the cache from building)
- dman 8y agoWhat version of gcc? What OS? I am showing ~0.4 seconds on a machine that is 3-4 years old. [PS: I think even 0.4 seconds is too slow]
- jandrese 8y agoC++'s templates (code!) in headers can cause a lot of pain on the compilation front. A simple #include <boost> can add many seconds to your compile.
- danbolt 8y agoRecently at work I was able to use C++ templates to automate a lot of repeated boilerplate code I was responsible for. The reason was to minimize the amount of (error-prone!) rote work that had to be done as the project would continue to scale. It worked out great, but I’ve noticed that the compilation time of translation units that use the templates have been growing linearly with features added. It’s not a lot in the big scheme of things, but it made me wish I could reason more about C++ compile times when I use its various features.
- pjmlp 8y agoYou can make use of libraries and external templates introduced in C++11.
- eximius 8y agoWell that's easy. Python doesn't compile anything. The old adage, 'the secret to writing fast code is writing code that does less' is true.
- pjmlp 8y agoPython2 is an interpreter. If you want to do a proper comparisasion you need to compare with a C++ interpreter. Or get a Python2 compiler to native code.
- bluGill 8y agoMy comparison is valid. Engineering is about tradeoffs. When considering python vs C++ cost of compiling is on factor, and cost of the run time is another. There are many other factors that you need to consider when deciding what language to use. The ability to compile python to native code is one as well.
- pjmlp 8y agoIt is not, because it is not the same execution model that is being compared, it is apples vs pears.