How to determine the maximum number to pass to make -j option?

I want to compile as fast as possible. Go figure. And would like to automate the choice of the number following the -j option. How can I programmatically choose that value, e.g. in a shell script?

Is the output of nproc equivalent to the number of threads I have available to compile with?

make -j1
make -j16