Article View: comp.lang.c
Article #34Re: Taming The Switch-Statement
From: bart
Date: Wed, 07 Oct 2026 18:41
Date: Wed, 07 Oct 2026 18:41
89 lines
5092 bytes
5092 bytes
On 07/10/2026 16:10, Waldek Hebisch wrote:
> bart <bc@freeuk.com> wrote:
>> What does that mean, work done at runtime? That shouldn't affect it.
>
> Yes.
>
>> The
>> compiler will only see a bunch of tokens related to the size of the source.
>
> You want useful result, that is why '-O'.
Apparently, -O means the same as -O1.
>> Recent discussions about headers suggested even huge headers were a
>> non-issue, according to some here.
>
> Normal headers, yes. To give you an idea what is involved let me show
> small part of header and the file. From 'arrpack.h':
>
> #define PROC1N(N1, N2, TYPE, OP, ARGS...) /* 1 array normal */ \
> int N1 ## A ## N2(ARGS TYPE *arr, int *spec) \
> { \
...> }
> ...
> #define PROC1(N1, N2, TYPE, OP, ARGS...) \
> PROC1N(N1, N2, TYPE, OP, ARGS) \
> PROC1M(N1, N2, TYPE, OP, ARGS) \
> PROC1I(N1, N2, TYPE, OP, ARGS)
...> PROC1(b, N2, unsigned char, OP, )
> PROC1(i, N2, int, OP, )
> PROC1(s, N2, float, OP, )
> PROC1(d, N2, double, OP, )
> PROC1(c, N2, __complex__ float, OP, )
> PROC1(z, N2, __complex__ double, OP, )
> #undef OP
> #undef N2
>
> As you can see this creates 18 not so small functions.
...
This generates about 5KB of code when expanded. You say the full version
is nearly 1MB? So what is the problem: generating that 1MB, or having to
process it?
It's roughly 30Kloc so if it is processing all that code, then it would
be the same problem as dealing with those big headers. Less in fact
since presumably it is only processed once if it contain function defs.
>> gcc -O0 465 KB
>> gcc -O1 348 KB>> gcc -O2 414 KB
>> gcc -O3 466 KB
>> gcc -Os 328 KB
>> If that means -O2 or -O3, then on my programs, it is more typically 2x
>> as fast, for C code. But more like 1.5 x as fast for the C code
>> transpiled from my language using my old transpiler, for language projects.
>
> I meant '-O'. In gcc '-O' means simpler and faster optimizations,
> which almost always lead to faster code. '-O2' means havier
> optimizations, and '-O3' even more heavy. Also, optimizations
> at '-O2' or '-O3' level may backfire: transformation that is
> intended to increase speed may actually decrease it.
OK, I've added -O1 to my table.
I rarely use it, because if I'm using gcc for its optimisations, then I
might as well get the best. In this case, Lua working on a Fibonacci
test gives these results:
gcc -O0 9.4 seconds
gcc -O1 3.1 seconds
gcc -O2 2.9 seconds
bcc 6.6 seconds
('bcc' is poor here partly because of how this project is written: full
of deeply nested macros and function calls. This seems to be typical of
interpreters written in C.
My own interpreter, written in plain code and running the same
benchmark, takes 1.2 seconds.)
> On high-end machines CPU frequently is quite powerful, but execution
> speed is limited by memory access. In such case executing say twice
> as many instructions as needed costs only a little. But on low end
> machines executing useless instructions cases significant slowdown.
>
Technical Details
Message-ID:
<11a63og$34v73$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <119uqnv$d6j2$1@dont-email.me> <20261005143559.157@kylheku.com> <11a1arj$1e8ks$1@dont-email.me> <11a295r$1lqal$3@dont-email.me> <11a2e2m$ef4o$2@dont-email.me> <11a2j83$1qu9n$1@dont-email.me> <11a2maf$1soc7$1@dont-email.me> <11a2vrn$20jj3$1@dont-email.me> <EI7xS.906$aNSb.21@fx20.iad> <11a37gv$23ruj$1@dont-email.me> <11a3vcj$88e7$1@paganini.bofh.team> <11a43hl$2e5k2$1@dont-email.me> <11a4h8v$eeb8$1@paganini.bofh.team> <11a574n$2pano$1@dont-email.me> <11a5nca$gg7c$1@paganini.bofh.team>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Wed, 7 Oct 2026 19:41:21 +0100 Organization: A noiseless patient Spider Lines: 89 Message-ID: <11a63og$34v73$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <119uqnv$d6j2$1@dont-email.me> <20261005143559.157@kylheku.com> <11a1arj$1e8ks$1@dont-email.me> <11a295r$1lqal$3@dont-email.me> <11a2e2m$ef4o$2@dont-email.me> <11a2j83$1qu9n$1@dont-email.me> <11a2maf$1soc7$1@dont-email.me> <11a2vrn$20jj3$1@dont-email.me> <EI7xS.906$aNSb.21@fx20.iad> <11a37gv$23ruj$1@dont-email.me> <11a3vcj$88e7$1@paganini.bofh.team> <11a43hl$2e5k2$1@dont-email.me> <11a4h8v$eeb8$1@paganini.bofh.team> <11a574n$2pano$1@dont-email.me> <11a5nca$gg7c$1@paganini.bofh.team> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 07 Oct 2026 18:41:21 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3308771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OSO7w5+7xUOTEiJVeNLPu"; posting-host="ddea08e9999a8df42a3f6de53c7cc773" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:n+4rppWCcRpIZiSN7ZGq34w4ZAg= sha256:1ibSGmD4vAZRxoTqO53bGE2Pwwj46LCatOolEnBaQ8Q= sha1:RvvUSj+EJghT34fSTMqg3s3UTe8= sha256:u9rtzYJcjs321sG7Dxx/d2SLC0hHfBJVz8AA3vexFjU= Content-Language: en-GB In-Reply-To: <11a5nca$gg7c$1@paganini.bofh.team>