GCC vs. Clang On The Apple M1 Under Arch-Based Asahi Linux

Written by Michael Larabel in Software on 19 April 2022 at 05:00 AM EDT.

With the Arch Linux based Asahi Linux running well on the Apple M1 (aside from accelerated graphics and various other features not implemented yet), one of the areas I was curious about was how well LLVM Clang and GCC C/C++ compilers compete when running on the Apple M1 with Linux. In this article are some quick benchmarks looking at how the stock compilers on Asahi currently compare for Apple's Arm-based SoC.

Using a 2020 Mac Mini with Apple M1 running Asahi Linux with all Arch Linux packages at the time, I ran a few dozen different benchmarks looking at how various open-source C/C++ workloads compare when being built under each compiler. GCC 11.2 and LLVM Clang 13.0.1 were the current packaged compilers available on Asahi Linux / Arch and used for this round of testing and the same CFLAGS/CXXFLAGS across testing -- the only change made during testing was switching out the compiler being used for building the software under test.

Apple M1 Compilers

For the vast majority of benchmarks the LLVM Clang vs. GCC performance was quite close, as we've come to see over the years on various AArch64 single board computers and server platforms. On the Apple M1 the performance was close and GCC in good standing. But for some workloads there were significant differences between the compilers:

Apple M1 Compilers

The NCNN neural network inference library from Tencent was performing hugely better when built under the GCC compiler. Across all of the different NCNN neural network benchmarks, the GCC 11.2 built binary held a commanding lead on the Apple M1. Meanwhile the LLVM Clang 13.0.1 compiler was performing the best in some of the Stress-NG synthetic benchmarks, consistently offering better performance for the Liquid-DSP digital signal processing software, and then for the many other tests was a mix between the two compilers and usually quite small.

Apple M1 Compilers

In total 72 different open-source C/C++ benchmarks were built and benchmarked under each compiler. GCC 11.2 in this initial Asahi Linux compiler testing saw GCC 11.2 lead about 58% of the time.

Apple M1 Compilers

If taking the geometric mean of all 72 benchmarks, GCC 11.2 led by about 13% over Clang.

That's the quick takeaways while all the individual benchmark results can be found on this OpenBenchmarking.org result page. As the Linux support on the Apple M1 matures I'll be back around with more compiler benchmarks especially with Clang 14.0 having just debuted (though not yet on Asahi/Arch as of testing) and GCC 12.1 also coming out in a few weeks as well as looking at the performance difference across various CFLAGS/CXXFLAGS configurations and more.

If you enjoyed this article consider joining Phoronix Premium to view this site ad-free, multi-page articles on a single page, and other benefits. PayPal or Stripe tips are also graciously accepted. Thanks for your support.

Related Articles
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.