Sujet : Re: Suggested method for returning a string from a C program?
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.cDate : 27. Mar 2025, 01:22:44
Autres entêtes
Organisation : To protect and to server
Message-ID : <vs25oi$2pqb$1@paganini.bofh.team>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
Kaz Kylheku <
643-408-1753@kylheku.com> wrote:
On 2025-03-26, Muttley@DastardlyHQ.org <Muttley@DastardlyHQ.org> wrote:
Whats this? You mean your amazing zippy fast compiler can't optimise for shit?
Maybe gcc isn't so bad after all eh?
Ah, but:
- gcc doesn't produce better code than it did 25 years go, when it
was at least an order of magnitude smaller and two orders faster.
At least not for tightly written programs where the C programmer
has done optimizing at the source level, so that the compiler has
little more to think about beyond good instruction selection and
cleaning up the pessimizations it has itself introduced.
No, gcc produces better code. Both 25 years ago and now one
can find situations where gcc output could be improved by
rather simple transformations, but it is less frequent now.
Concerning "optimizing at the source level", modern machines
have instructions that can not be directly expressed at
source level, but which can speed up resulting programs.
In particular vector instructions. Modern gcc is smart enough
to realize that code using separate scalar variables perform
some (not all!) operations in parallel and use vector
instructions.
How much improvement? Probably in 5-15% range on average
programs for hand-optimized programs.
Concerning size, you are right, there is significant increase in
size. Concerning speed, that is debatable. On the same machine
the same somewhat silly file containing just declarations needs
9.894s using gcc-12.2 and 10.668s using gcc-3.4.6. Different
silly example containg trivial code needs 27.947s using gcc-12.2
and 12.627s using gcc-3.4.6. Both were at default setting
(no optimization). As you see, depending on content of the
file gcc-12.2 can be slightly faster or few times slower than
gcc-3.4.6 when doing non-optimizing compilation.
Modern gcc can do whole-program optimization, which can take
a lot more time than function-by-function optimization done
by gcc-3.4.6. But IME on realistic programs (in particular
split into moderately sized files) optimization increases
time, but that is few times, both for gcc-12.2 and for
older versions. In other words, typically optimization
does not lead to catastrophic increase in compile time,
both for modern and old gcc.
-- Waldek Hebisch