free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ have Virtual Function vs Function Pointer call 2011
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
Which is faster ?
A. Call 1000 times a virtual function OR
B. call 1000 times a normal function trough a function pointer.

For example:

A.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Base
{
public: virtual void myfunc() = 0;
};

class Child: public Base
{
public: void myfunc(){...}; //overriding the base class function
}

int main()
{
Child myclass;

call myclass.myfunc() 1000 times
}



B.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class SomeClass
{
public: void myfunc(){ ... }
};

int main()
{
SomeClass myclass;

void (*foo)();
foo = &myclass.myfunc;

call foo() 1000 times
}


What do You guys think which one would perform better ?
Assume that the compiler will surely not be able decide the class type in the virtual function case (A). And also the functions are quite complex and big.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why we use inline function if there are simple function available, or what is the spa Vuhelper 0 22,008 05-31-2012, 01:51 AM
Last Post: Vuhelper
  Default Function Argument with example Vuhelper 0 13,370 05-31-2012, 01:47 AM
Last Post: Vuhelper
  What is the difference among calloc function ,malloc function and recalloc function? Vuhelper 0 34,633 05-31-2012, 01:46 AM
Last Post: Vuhelper
  What is Function Overloading in C++ Vuhelper 0 5,437 05-31-2012, 01:45 AM
Last Post: Vuhelper
  offline function in C++ Vuhelper 0 3,666 05-31-2012, 01:42 AM
Last Post: Vuhelper
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 3,033 05-31-2012, 01:40 AM
Last Post: Vuhelper
  how we used the 1-calloc Function 2- malloc Function 3- free () 4- realloc Function i Vuhelper 1 31,180 05-31-2012, 01:35 AM
Last Post: Vuhelper
  What are the function of IO ports in C++ Vuhelper 0 3,632 05-31-2012, 01:27 AM
Last Post: Vuhelper
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 1,972 01-06-2012, 12:24 AM
Last Post: Vuhelper
  Argc(argument count) and argv(argument value) are used in main function Vuhelper 0 2,058 01-04-2012, 10:42 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support