Skip to content

Instantly share code, notes, and snippets.

@turugina
Created March 10, 2011 02:42
Show Gist options
  • Save turugina/863481 to your computer and use it in GitHub Desktop.
Save turugina/863481 to your computer and use it in GitHub Desktop.
#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