3 ms·
Okay, but as far as I know "inline" is just a suggestion for the compiler. Depending on the complexity of the function or the phase of the moon the compiler can
by adrianN 4y ago
Okay, but as far as I know "inline" is just a suggestion for the compiler. Depending on the complexity of the function or the phase of the moon the compiler can choose not to inline it. I wouldn't want to rely on that for a critical piece of my performance.
- flohofwoe 4y agoTrue, that's what I mean with depending too much on the optimizer (in a sibling comment). But IME the threshold for inlining code is surprisingly big (which of course also has a downside: potential code bloat). I added a little fix which prevents the compiler from discarding the result completely (just by going through __builtin_printf()): https://godbolt.org/z/W93WrhbaE https://godbolt.org/z/W93WrhbaE PS: another minor tweak (make the comparison function static, so that no extra copy is included in the compiler output): https://godbolt.org/z/5TTM4x193 https://godbolt.org/z/5TTM4x193
- evmar 4y ago`static` also allows it to optimize, and it's more of a code hygiene thing. Your original code as written unintentionally defines `find` as a function that must be preserved (as a separate function) into the compiled output, and `static` undoes that.