Zig CC gets significantly lower Coremark than Gcc

I ran a simple experiment and it showed that zig cc (using clang) results in significantly lower Coremark ratings than using gcc.

Below are the two ratings:

  • CoreMark 1.0 : 30487.804878 / Clang 18.1.6 (GitHub - ziglang/zig-bootstrap: take off every zig 98bc6bf4fc4009888d33941daf6b600d20a42a56) -O2 -DPERFORMANCE_RUN=1 -lrt / Heap
  • CoreMark 1.0 : 37539.886129 / GCC13.2.0 -O2 -DPERFORMANCE_RUN=1 -lrt / Heap

These were run on my Ubuntu 24.04 PC via:

git clone https://github.com/eembc/coremark.git
cd coremark
export PATH=<path to zig>:$PATH
make clean && make && cat run1.log
make clean && CC="zig cc" make && cat run1.log
1 Like

I’m not sure what you think is interesting about this.

Does it give lower CoreMark ratings than clang?

Because if you’re racing clang and gcc that has nothing to do with Zig. If you wanted to race clang and zig cc and the scores were substantially different, that might be interesting.

4 Likes

Yes, I agree I was racing gcc and clang. If not interesting, please feel free to ignore.

The medium-term plan for Zig is for the LLVM dependency, and therefore the zig cc compiler, to be an optional part of a Zig system. The main issue is #16720, which links to the rest of them.

By that same token it might well be possible to provide gcc as an option for integrating with Zig, but that would be a lot of work which interested parties would have to do.

In the meantime, when you invoke zig cc, you get clang. GCC and clang have a lot of people working hard to make them efficient, some benchmarks favor one, some favor the other.

What I meant to indicate is just that Zig as a language can’t do anything about that. Even if the team wanted to take some time to buff up zig cc performance, that would have to be done by improving clang or LLVM, not Zig.

A difference between zig cc and clang, however, might be actionable. But for structural reasons it’s also unlikely.

1 Like

On debian 12 (bookworm), i7-14700:

2 Likes

help me increase my understanding…

if that’s the case, why would there ever be a difference between zig cc and clang (assuming the same LLVM version)???

i’m also a little confused by this issue, which suggests there is a difference… sounds like one could/should use zig build-exe over zig cc to gain finer control over optimization???

but let’s pop back up and allow me to ask the following question:

given a body of legacy C code (eg, CoreMark), how to i generate the “fastest” executable using zig without modifying the sources???

while CoreMark is nominally used to measure CPU performance, in practice it has become a standard C compiler benchmark per se… using whatever combination of (zig build-exe) options it takes, how would i maximize speed over space???

i’m less concerned how the various -O? options map… anytime i move to a “new” C compiler, i’m well prepared to make whatever adjustments are needed to maximize performance…

@dimdin – could you explain what the -target x86_64-linux option does to improve the score from 39K to 43K (iterations per second)???