Benchmarks: Function Call

0 Flares Twitter 0 Facebook 0 Google+ 0 Pin It Share 0 Email -- Filament.io 0 Flares ×

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:

Get Adobe Flash player

I’ll post my results in the comments below.

0 Flares Twitter 0 Facebook 0 Google+ 0 Pin It Share 0 Email -- Filament.io 0 Flares ×

1 Comment

  1. Interesting to see that even when accessed through an external object, it is faster than when using a reference of a function. Also, passing arguments to it slows down the process.

    Functions (direct, public, static, no arg): 0.14100000000000001
    Functions (object, direct, override, public, no arg): 0.149
    Functions (object, direct, public, no arg): 0.15
    Functions (direct, public, 4 args): 0.162
    Functions (direct, public, no arg): 0.184
    Functions (by ref, public, static, ext, no arg): 0.328
    Functions (by ref, public, static, no arg): 0.332
    Functions (object, by ref, public, no arg): 0.335
    Functions (by ref, public, no arg): 0.357
    Functions (by ref, public, 4 args): 0.47900000000000004
    Functions (by ref, public, static, 4 args): 0.482

Leave a Comment

*