Why is inlining considered faster than a function call?

前端 未结 16 1574
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 04:04

Now, I know it\'s because there\'s not the overhead of calling a function, but is the overhead of calling a function really that heavy (and worth the bloat of having it inli

16条回答
  •  醉话见心
    2020-12-13 04:30

    A typical example of where it makes a big difference is in std::sort which is O(N log N) on its comparison function.

    Try creating a vector of a large size and call std::sort first with an inline function and second with a non-inlined function and measure the performance.

    This, by the way, is where sort in C++ is faster than qsort in C, which requires a function pointer.

提交回复
热议问题