To speed up the gcc's compilation time, we have two options:
However, I don't know which is better under what circumstances.
I have googled this question, and get some vague impression that ccache is totally excel the other. Is that right?
Precompiled headers, and ccache, are for entirely different use cases. ccache can be used together with precompiled headers, they are not mutually exclusive.
ccache caches the entirety of a given source file, headers and all, caching the compiled object module. Technically, ccache takes the entire preprocessed source translation unit, hashes it, and caches the resulting object module.
Precompiled headers provide a little bit of time savings when the same header files are #include
d repeatedly from different source translation units. But if the same source code gets repeatedly compiled, precompiled headers don't help (beyond the sole benefit of using the precompiled header). That's where ccache comes in, with ccache quietly skipping the entire compilation phase, and just fetching the previously-compiled object module from the cache.
So, it's not really meaningful to compare which approach is better, ccache or precompiled headers. They solve two different problems.