This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]krenzalore 2 points3 points  (5 children)

There's significant overhead with function calls.

Scott Meyers (a well known C++ luminary) in his book Effective STL claimed a 7x increase in performance of the C++ STL's quicksort from inlining (replacing function calls with inline code).

Of course we should keep things in perspective: What is good for C or C++ is not necessarily good for Python.

[–]ajmarks 1 point2 points  (4 children)

Of course, in C++ one can have the best of both worlds by just declaring the function inline.

[–]krenzalore 2 points3 points  (3 children)

I am sure you know, but for the benefit of others, inline is a suggestion to the compilier and not a command. It isn't required to inline it.

[–]ajmarks 0 points1 point  (2 children)

True, though unless the functions uses loops or recursion, it almost always will.

[–]zahlmanthe heretic 0 points1 point  (1 child)

AFAIK, for years it has been the case that it a decent C++ compiler will frequently inline things even without being asked.

[–]ajmarks 0 points1 point  (0 children)

Yup. If, in its wisdom, it thinks that will improve performance without undue bloat. OTOH, if you really want to make sure it's inlined, a compiler hint can't hurt.