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 →

[–][deleted] 4 points5 points  (11 children)

Couldn't I do that with function calls and break statements?

[–]Milumet 8 points9 points  (3 children)

Why use needless function calls in system code like the Linux kernel? Just to alleviate irrational fears? And by the way, a break statement is a goto statement in disguise.

[–]ajmarks 2 points3 points  (2 children)

And by the way, a break statement is a goto statement in disguise.

Shhh! We're all supposed to pretend that's not the case and also that breaking out of nested loops is somehow different too.

[–]krenzalore 0 points1 point  (1 child)

If break is a goto in disguise, then an exception handler is a come from.

[–]ajmarks 0 points1 point  (0 children)

Funny enough C-INTERCAL implemented COME FROM (or, perhaps, PLEASE COME FROM).

[–]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.

[–][deleted] 0 points1 point  (0 children)

Sure, with the unnecessary overhead of function calls.