Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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();
}
like image 580
codekiddy Avatar asked Dec 28 '22 08:12

codekiddy


1 Answers

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).

like image 69
Tony Delroy Avatar answered Jan 30 '23 13:01

Tony Delroy