c++ - If a function is only called from one place, is it always better to inline it? -
this question has answer here:
- when use inline function , when not use it? 13 answers
if function used in 1 place , profiling shows it's not being inlined, there performance advantage in forcing compiler inline it?
obviously "profile , see" (and in case of function in question, did prove small perf boost). i'm asking out of curiosity -- there performance disadvantages reasonably smart compiler?
no, there notable exceptions. take code example:
void do_something_often(void) { x++; if (x == 100000000) { do_a_lot_of_work(); } } let's do_something_often() called , many places. do_a_lot_of_work() called (one out of every 1 hundred million calls). inlining do_a_lot_of_work() do_something_often() doesn't gain anything. since do_something_often() nothing, better if got inlined functions call it, , in rare case need call do_a_lot_of_work(), call out of line. in way, saving function call every time, , saving code bloat @ every call site.
Comments
Post a Comment