Reputation: 9863
First of all, let me clarify my question is totally unrelated to Is there any benefit to passing all source files at once to a compiler?.
What I'd like to know here is whether my build-times would become faster if i made:
a) Many number of calls to the compiler with one single file each
b) Few number of calls to the compiler with many files each
c) Moderate number of calls to the compiler with a bunch of files each
Why am I asking this? I'm in the middle of creating a ninja generator (similar to the bunch here and I'd like to know what's the best way to create the dependency DAG.
You could claim spawning less subprocesses will be typically faster and less expensive but i'd like to know whether the gains would be worth or not so I can design my tool properly.
Just to clarify a little bit further, here's a simple example, as you can see in that build.ninja file there are many build statements with a 1:1 dependency per compiler call, so... could the build times improved by grouping few source files on single build statements?
EDIT: Also, I guess this Why is creating a new process more expensive on Windows than Linux? can provide some insights for the current topic
Upvotes: 3
Views: 291
Reputation: 28997
It depends. (But you knew that was going to be the answer to a "is it faster to ..." question, didn't you?)
Using MSVC it is much faster to compile all the files with a single call to the compiler. It's not just that process creation is slow on Windows, the compiler also takes quite a long time to initialize itself. (Of course, the speed-up going from twenty-at-a-time to all-at-once will probably be much less than going from one-at-a-time to twenty-at-a-time.)
Using gcc/clang on Linux, it is probably faster to compile one file at a time. This is not so much because gcc is faster like this, but because you can use ccache (ccache will only optimize if given a single file to compile), and ccache makes compilation much faster. (Obviously, if all your files are different every time - because they are generated with unique content - ccache won't help.) The same applies to mingw on Windows.
Upvotes: 2