views:

113

answers:

2

Hi,

What's the best value of -j switch?

I usually set this up to the number of CPU/Cores available.

Thanks.

+11  A: 

I've always seen the number of cores available plus 1 as the recommended value

Michael Mrozek
The idea behind the +1 being that it helps keep the processor(s) doing something while they're waiting on disk I/O for the next source file.
Tyler McHenry
Agreed, plus 2 worked well for me. Heavy disk usage.
Hans Passant
+3  A: 

Just measure.

Start with the number of cores. And then add one until you feel that you get diminishing returns.

quamrana
+1 Experiment is the only real way to go here. I've written a fair amount of multi-threaded code that was I/O bound, and you can normally increase the number of threads well over the number of processors and still get performance increases. Then at some point the performance drops off , often quite dramatically.
anon
I'm kind of torn here, whether this is a good idea or not. At some point, you get increased performance only because the threads take up a bigger timeslice. That's not a very good idea. Rather, if the build process is that important, one should rather use less threads and raise the `nice`'ness level.
Mads Elvheim
@Mads: What I'm talking about here is that a build process can be doing lots of disk access. A number of threads can quickly be blocked waiting for the disk, meanwhile the others (one per core) can be doing actual compiling.
quamrana