Is Clang slower than GCC?
Sometimes a program is a lot faster when compiled with GCC, sometimes it's a lot faster with clang. Usually it's marginally faster with GCC. Clang attempts to unroll loops really, really aggressively. Even at -O2 : Clang's loop unrolling attempts at -O2 are more aggressive than GCC's loop unrolling attempts at -O3 .
Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.
Why is Clang so much slower compiling than MSVC? That's not how clang works. It creates objects specialized for target architecture at beginning and there is no "unused code" to fetch or incorrectly predict (most of the time). The slowness comes from way how compiler is structured / architected.
At -O2 optimization Clang's 619 build is 46% faster than its 301 build: at -O3 Clang's improvement is 31%. Good, but at each optimization level GCC's 619 build is more than twice as fast as its 301. GCC more than reverses Clang's former superiority. And at each optimization level GCC now beats Clang by 17%.
Clang is designed to provide a frontend compiler that can replace GCC. Apple Inc. (including NeXT later) has been using GCC as the official compiler.
...
GCC Vs Clang.
Criteria | GCC | Clang/LLVM |
---|---|---|
Code modularity | Monolithic | Modular |
Supported platforms | *inx, Windows (MinGW) | *inx, Natively in Windows |
While LLVM and GCC both support a wide variety languages and libraries, they are licensed and developed differently. LLVM libraries are licensed more liberally and GCC has more restrictions for its reuse. When it comes to performance differences, GCC has been considered superior in the past.
The LLVM-based Clang and Zapcc compilers produce executables with average performance but feature amongst the fastest compilers in the suite. The Zapcc is the fastest compiler in our compile test.
When I switched to both clang and MSVC 64-bit versions, I see MSVC is faster than clang by about 1.5X. On 32-bit toolsets, I saw that MSVC is 2X slower than Clang. This, however, is totally believable because MSVC performance is tracked mostly on the 64-bit toolset.
Cloning the repositories takes a few minutes, then the actual build step will take between 7 minutes to 1 hour, depending on your hardware.
Why does Apple use Clang?
The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets.
Apple uses a specialized version of GCC 4.0 and 4.2 in Leopard's Xcode 3.1 that supports compiling Objective-C/C/C++ code to both PowerPC and Intel targets on the desktop and uses GCC 4.0 to target ARM development on the iPhone.
...
Difference between GCC and G++
g++ | gcc |
---|---|
g++ can compile any .c or .cpp files but they will be treated as C++ files only. | gcc can compile any .c or .cpp files but they will be treated as C and C++ respectively. |
Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel, and AMD. Clang 14, the latest major version of Clang as of March 2022, has full support for all published C++ standards up to C++17, implements most features of C++20, and has initial support for the upcoming C++23 standard.
Each library supports a particular component in a typical compiler pipeline (lexing, parsing, optimizations of a particular type, machine code generation for a particular architecture, etc.). What makes it so popular is that its modular design allows its functionality to be adapted and reused very easily.
Clang is not just like any other compiler, it comes with an Infrastructure that allows it to build tools and it can also extend its behaviors easily. The LLVM/Clang source code includes many tools while others are available on the web. Clang can be used as a very good C/C++ parser for building tools.
With 1 parallel copy, UnixBench compiled with Intel's is about 20% faster than the version compiled with GCC.
C++20 implementation status
Clang has support for some of the features of the ISO C++ 2020 standard. You can use Clang in C++20 mode with the -std=c++20 option (use -std=c++2a in Clang 9 and earlier).
Clang is a completely separate compiler (written entirely from scratch, using LLVM). You don't need GCC to use Clang, as can be shown in the case of FreeBSD (they completely replaced GCC with Clang/LLVM and don't install GCC in the base anymore for licensing reasons).
When I switched to both clang and MSVC 64-bit versions, I see MSVC is faster than clang by about 1.5X. On 32-bit toolsets, I saw that MSVC is 2X slower than Clang. This, however, is totally believable because MSVC performance is tracked mostly on the 64-bit toolset.
Does Clang need GCC?
Clang is a completely separate compiler (written entirely from scratch, using LLVM). You don't need GCC to use Clang, as can be shown in the case of FreeBSD (they completely replaced GCC with Clang/LLVM and don't install GCC in the base anymore for licensing reasons).
The GNU compiler collection, GCC, is one of the most famous open-source tools in existence. It is a tool that can be used to compile multiple languages and not just C or C++. The current version of GCC, GCC 11, has full support for C++17 core language features as well as C++17 library features.
Clang is compatible with GCC. Its command-line interface shares many of GCC's flags and options. Clang implements many GNU language extensions and compiler intrinsics, some of which are purely for compatibility.