Which is faster ?View more random threads:
- i solve the assignment i mean which ms word doc file can i...
- if we have a program to check, how we can tell how many...
- Sorting code in c++
- How many types of Array are there in C++?
- GUI for DOS
- Q: What is the difference between function declaration and...
- Configuring openAL in Dev C++
- Compound assignment +=, -=, *=, /=, %=, >>=, <<=, &=, ^=,...
- when we make codes in Devc++ after press F9 (compiling) the...
- Multidimensional Array vs If-Statements and Functions? in...
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;
Sponsored Links
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.