The performance of ccache depends on a lot of factors, which makes it quite hard to predict the improvement for a given use case. This page contains some different performance measurements that try to give an idea about the potential speedup.
It should also be noted that if the expected hit rate is low, there may be a net performance loss when using ccache because of the overhead of cache misses (typically 5%-20%). Also, if the build machine is short on memory compared to the amount of memory used by the build tools (compiler, linker, etc), usage of ccache could decrease performance due the fact that ccache's cached files may flush other files from the OS's disk cache. See this mailing list post by Christopher Tate for a good write-up on this issue. So to sum it up: it is probably wise to perform some measurements with and without ccache for your typical use case before enabling it!
The following measurements were made on a fairly standard Linux-based desktop system with an Intel Core i5-4690K and a standard SSD disk.
“ccache 3.7.1 direct” in the tables below means running ccache with direct mode enabled (which is the default) and “ccache 3.7.1 prepr.” means running ccache with a disabled depend mode, thus falling back to the preprocessor mode. “ccache 3.7.1 depend” means running ccache with the depend mode enabled.
All results were gathered by timing 100 individual compilations and picking the median result.
Here are the results of building ccache's own
-g -O2 -MD and needed
|Without ccache||0.6988 s||100.00 %||1.00 x|
|ccache 3.7.1 prepr., first time||0.7251 s||103.77 %||0.96 x|
|ccache 3.7.1 prepr., second time||0.0247 s||3.53 %||28.33 x|
|ccache 3.7.1 direct, first time||0.7268 s||104.01 %||0.96 x|
|ccache 3.7.1 direct, second time||0.0048 s||0.69 %||145.39 x|
|ccache 3.7.1 depend, first time||0.7102 s||101.64 %||0.98 x|
|ccache 3.7.1 depend, second time||0.0051 s||0.73 %||137.81 x|
As can be seen above, cache hits in the direct mode are about 5 times faster than in the preprocessor mode. The speedup compared to compiling without ccache is very large since the compilation costs a relatively large amount of CPU time. The overhead of cache misses can also be seen, but it's smaller for the depend mode.
This is a test that aims to measure preprocessor-intensive compilation.
Here, c++_includes.cc (a file including nine
common include files from the C++ standard library) was compiled without any
special flags other than
-MD to enable usage of the depend
|Without ccache||0.2421 s||100.00 %||1.00 x|
|ccache 3.7.1 prepr., first time||0.2892 s||119.46 %||0.84 x|
|ccache 3.7.1 prepr., second time||0.0496 s||19.65 %||5.09 x|
|ccache 3.7.1 direct, first time||0.2919 s||120.58 %||0.83 x|
|ccache 3.7.1 direct, second time||0.0083 s||3.35 %||29.10 x|
|ccache 3.7.1 depend, first time||0.2495 s||103.08 %||0.97 x|
|ccache 3.7.1 depend, second time||0.0083 s||3.41 %||29.32 x|
The difference between direct and preprocessor mode hits is about a factor 6 — slightly higher than for the ccache.c test because the preprocessor overhead is higher. The depend mode really shines here since running the preprocessor on cache misses in the depend mode is costly.