Created
March 10, 2011 02:42
-
-
Save turugina/863481 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <limits> | |
#include <boost/timer.hpp> | |
struct BitTest { | |
int i; | |
bool a : 1; | |
}; | |
struct Test { | |
int i; | |
bool a; | |
}; | |
void test1(int max) { | |
BitTest bt; | |
for (int i = 0; i < max; ++i) { | |
bt.a = i%2; | |
} | |
} | |
void test2(int max) { | |
Test t; | |
for (int i = 0; i < max; ++i) { | |
t.a = i%2; | |
} | |
} | |
int main() | |
{ | |
const int max =std::numeric_limits<int>::max(); | |
boost::timer t; | |
t.restart(); | |
test1(1000); | |
test2(1000); | |
t.elapsed(); | |
t.restart(); | |
test1(max); | |
const double e1 = t.elapsed(); | |
t.restart(); | |
test2(max); | |
const double e2 = t.elapsed(); | |
std::cout << "(" << max << ") " << e1 << ", " << e2 << "\n"; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment