Re:When static makes your C code 10 times faster
by rostayob on Sunday July 04, 2021 @01:05PM
(#27731082)
Author here -- I agree that const is better. The perf difference I encountered was due to the static keyword though, which is why the blog post talks about that specific issue.
[ Parent
| on HN ]
Re:When static makes your C code 10 times faster
by 95014_refugee on Sunday July 04, 2021 @02:05PM
(#27731478)
The perf difference was due to the compiler being able to infer 'const' by way of 'static'.
Advocating 'static' when your actual intent is 'const' does less experienced readers a disservice; they will assume that 'static' is meant to make things faster, and be disappointed when it doesn't work for non-constant values.
Re:When static makes your C code 10 times faster
by rostayob on Sunday July 04, 2021 @02:16PM
(#27731560)
I am not advocating static. I'm advocating for looking at what the compiler outputs when surprising behavior is encountered. The example is extracted from a larger piece of code, and I reported the minimal case as-is.
If anything, the title is meant to be read as "isn't it amusing that something apparently unrelated such as `static` causes a performance improvement".
That said, I have added a note clarifying this at top of the post now.
Re:When static makes your C code 10 times faster
by 8bitsrule on Monday July 05, 2021 @12:52AM
(#27734722)
I thought you made your point neatly and succinctly. Code can be optimized on multiple levels; the compiled result is clearly more efficient. This lesson applies regardless of the language being compiled.