Created
March 29, 2009 20:42
-
-
Save hipertracker/87516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctime> | |
#include <iostream> | |
using namespace std; | |
static int i = 0; | |
struct A { | |
virtual void perform() { | |
i++; | |
} | |
}; | |
struct B : public A { | |
void perform() { | |
i += 4; | |
} | |
}; | |
void bench(); | |
int main() { | |
bench() | |
bench() | |
bench() | |
bench() | |
bench() | |
cout << i << endl; | |
return 0; | |
} | |
void bench() { | |
clock_t cstart = clock(); | |
A*a = new A(); | |
A*b = new B(); | |
for (int i=0;i<400000000;i++) { | |
A*x = (i & 1) == 0 ? a : b; | |
x->perform(); | |
} | |
delete a; | |
delete b; | |
clock_t cend = clock(); | |
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC; | |
cout << millis << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment