How to speed up compilation time in linux
I use a non-recursive build system based on GNU make and I was wondering how well it scales.
I ran benchmarks on a 6-core Intel CPU with hyper-threading. I measured compile times using -j1
to -j20
. For each -j
option make
ran three times and the shortest time was recorded. Using -j9
results in shortest compile time, 11% better than -j6
.
In other words, hyper-threading does help a little, and an optimal formula for Intel processors with hyper-threading is number_of_cores * 1.5
:
Chart data is here.
Linux Kernel Compilation speed up command
Well I am not expert but from my experience:
- set -J parameter same as your processors if you have 8 then make it
8, you can check from 'cat /proc/cpuinfo
' - If its virtual machine make sure you have hyper enabled and
virtual machine is using more than one physical cpu core - Dont use toolchain and try to compile at the same target
architecture (i.e. if its amd64 then compile at amd 64 bit
machine)
**EDIT:
(Update from Andy comment) Check ccache and how its used in kernel compilation: http://linuxdeveloper.blogspot.de/2012/05/using-ccache-to-speed-up-kernel.html
Additional note: Also make sure you squeeze your CPU enough https://askubuntu.com/questions/523640/how-i-can-disable-cpu-frequency-scaling-and-set-the-system-to-performance
How to speed up g++ compile time (when using a lot of templates)
What has been most useful for me:
- Build on a RAM filesystem. This is trivial on Linux. You may want to keep a copy of common header files (precompiled or the actual .h files) on the RAM filesystem as well.
- Precompiled headers. I have one per (major) library (e.g. Boost, Qt, stdlib).
- Declare instead of include classes where possible. This reduces dependencies, thus reduces the number of files which need to be recompiled when you change a header file.
- Parallelize make. This usually helps on a case-by-case basis, but I have
-j3
globally for make. Make sure your dependency graphs are correct in your Makefile, though, or you may have problems. - Use
-O0
if you're not testing execution speed or code size (and your computer is fast enough for you not to care much about the (probably small) performance hit). - Compile each time you save. Some people don't like this, but it allows you to see errors early and can be done in the background, reducing the time you have to wait when you're done writing and ready to test.
Related Topics
How to Set Up My Linux X Terminal So That Emacs Has Access to 256 Colors
I Can't Execute Command Modprobe Vboxdrv
Shell Script to Copy and Prepend Folder Name to Files from Multiple Subdirectories
What Does "$1/*" Mean in "For File in $1/*"
How to Update Cudnn to a Newer Version
Cannot Create Backup File(Add ! to Overwrite)
When Should the Option Remainafterexit Needs to Be Set True When Creating New Systemd Services
Execution Time of an SQLite Query: Units
Installing Qt on Linux, Cannot Find -Lgl
How to Check If Find Command Didn't Find Anything
Prepend Data from One File to Another
Linux, Print All Lines in a File, Not Starting With
Installing G++ on Windows Subsystem for Linux
What Does This Command Do? "Exec Bash -L"