public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Why gcc's code is so much slower than clang's?
@ 2023-10-23 13:30 Georg-Johann Lay
  2023-10-23 14:27 ` Alexander Monakov
  2023-10-23 14:39 ` David Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Georg-Johann Lay @ 2023-10-23 13:30 UTC (permalink / raw)
  To: gcc-help

For the C code below, I am getting execution times of around 8 to 8.3
seconds with gcc (v11.3 and v13.2) and around 5 seconds with clang v17.

Only options I used were -O3 (-Os or -Ofast didn't make a difference).

Architecture is x86_64-linux-gnu, Dual Core Intel Core2

I ran the code below with

 > gcc coll.c -o coll.x -O3 && time -p ./coll.x

I wouldn't ask this question if I hadn't observed similar thing
with other programs already, any I am wondering if I am missing
something crucial like supplying GCC with better options?

After all, it's that GCC's code is 60% (or more) slower than clang's.

I'd guess +-5% is well in the range of noise, but +60% or more ???

Johann

---

C99 Code:


#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

uint32_t coll (uint64_t i)
{
     for (uint32_t n = 0; ; ++n)
     {
         if (i == 1)
             return n;

         if (i > UINT64_MAX / 3 - 3)
         {
             fprintf (stderr, "%" PRIu64 " = %" PRIx64 " too big\n", i, i);
             exit (1);
         }

         i = (i & 1)
             ? (3 * i + 1) >> 1
             : i >> 1;
     }
}

int main (void)
{
     uint64_t n  = 0x1000000;
     uint64_t i0 = 0x2000000;
     uint32_t max_it = 0;

     for (uint64_t i = i0; i <= i0 + n; ++i)
     {
         uint32_t it = coll (i);
         if (it > max_it)
         {
             printf ("%" PRIu64 ": %" PRIu32 "\n", i, it);
             max_it = it;
         }
     }

     return 0;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-23 16:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 13:30 Why gcc's code is so much slower than clang's? Georg-Johann Lay
2023-10-23 14:27 ` Alexander Monakov
2023-10-23 15:50   ` Xi Ruoyao
2023-10-23 16:23     ` Alexander Monakov
2023-10-23 14:39 ` David Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).