Another benchmark about function calls.
There already is a really good article at JacksonDunstan.com but here I focus on functions I’m particularly interested in:
- public function (direct / static / no argument / 4 args)
- function reference (direct / static / no argument / 4 args)
- overridden function
- function accessed from external object (direct / by reference)
From my results, I can tell you that the fastest is, without surprise, the direct function (call the function directly by its name inside of the same class, what we usually do…) but what surprised me was that the function accessed through another object (object.function01();) was as fast as the function from the same class… interesting.
Functions by reference are slower, but static functions are even more. I also tried to pass a couple of arguments as well and those are of course the slowest.
Also, overriding a function doesn’t seem to cost anything…
I need to see which one of these is faster in order to implement the best solution for an animation engine in ND2Dx (as well as a Final State Machine)
Here is the test machine in the mean time:
I’ll post my results in the comments below.