the "price" of a context switch/function call

Geoff Canyon gcanyon at gmail.com
Thu Oct 9 18:17:45 EDT 2014


I took just about the worst case scenario: a single-line function I wrote a
few weeks back:

function isLeapYear Y
  return Y is a number and Y mod 4 = 0 and (Y mod 100 > 0 or Y mod 400 = 0)
end isLeapYear

If any function is going to pay the price for the cost of a function call,
that's it -- there's minimal work to do in the actual function, so any
overhead will be that much worse in proportion to how little actual work
there is.

Calling that with i = 1 to a million takes just over a second on my
computer. If I inline the function, it takes 0.25 to 0.3 of a second. So
the speed-up for inlining is substantial -- the overhead of calling the
function is greater than the time spent on the actual code. But it's still
not that bad. And any function with more than a few lines of code in it
will be much less affected.



More information about the use-livecode mailing list