codekiddy
codekiddy

Reputation: 6137

C++ What's faster? static member function or ordinary one?

I'm trying to studdy some performace things... this question may sound stupid, but I'll give it a try. Let's assume each function has 100 lines of same code. or does this difference dosn't realy metter? which one will be faster on execution in main function:

struct A
{
    static void f()
         {
               cout << "static one";
         }
};

or this one:

void f()
{
   cout << "non static";
}

int main()
{
      A::f();
      f();
}

Upvotes: 4

Views: 1624

Answers (1)

Tony Delroy
Tony Delroy

Reputation: 106096

There's no difference, the compiler works out the address at compile time and dispatches execution to it in one step at run-time (if it doesn't inline it, which it's equally able/likely to do with either).

Upvotes: 10

Related Questions