Question casually profiling Clang vs GCC

Hi,

I am a long term Gentoo Linux user, which, as a source-based meta
distribution, involves frequent (re-)compilation of a lot of packages
from scratch.

Curious how Clang would perform against the system's gcc-7.3.0-r3 in
terms of compilation speed, I installed clang-5.0.2 (latest stable on
Gentoo) and compiled a handful of random packages: Python, unzip,
libopus, exim, nginx, postresql. Setting was -O2, LTO was disabled.

Surprisingly, Clang consistently took considerably longer to compile
these packages than GCC, ranging from +28% (unzip) to +54% (postgresql),
with a median increase of +40% in compile time. That contradicts the
notion that Clang would be on par or quicker than GCC in terms of
compilation time.

Is that expected behaviour? May I have been missing some vital switch or
setup?

Any hints appreciated, and I'll gladly provide more information.

Kind regards,

Florian

Hi,

very interesting. My experience with normal compilation is, that clang
is faster.

Could it be, that there are some precompiled headers or similar present
on the system, that GCC utilizes?

Best Regards, Jonas

very interesting. My experience with normal compilation is, that clang
is faster.

Here's the data. It's from a single run each, so it's nowhere near a
statistically sound sample.

Package GCC Clang Difference

dev-lang/python-2.7.15 2:31,640s 3:36,891s +43%
app-arch/unzip-6.0_p21-r2 0:07,859s 0:10,094s +28%
media-libs/opus-1.2.1 0:34,218s 0:46,750s +37%
mail-mta/exim-4.91-r2 0:39,779s 0:54,672s +37%
www-servers/nginx-1.12.2-r1 0:43,378s 1:03,537s +46%
dev-db/postgresql-10.3 4:03,518s 6:14,859s +54%
media-gfx/inkscape-0.92.2 28:21,146s 34:52,015s +23%

Could it be, that there are some precompiled headers or similar present
on the system, that GCC utilizes?

That is possible. Where and how would I check that?

Cheers,
    Florian

Hi Florian,

Precompiled headers are supposed to live side-by-side with their
source headers, according to:

So you can probably do something like `find /usr/include -name
"*.gch"` to see if there are GCC precompiled headers available.

(Not sure where you should be searching in Gentoo to catch all
headers, but you should be able to figure it out)

Cheers,
- Kim