Skip to content

Instantly share code, notes, and snippets.

@komiga
Created December 22, 2013 22:57
Show Gist options
  • Save komiga/8089447 to your computer and use it in GitHub Desktop.
Save komiga/8089447 to your computer and use it in GitHub Desktop.
#include <bitset>
#include <vector>
#include <chrono>
#include <iostream>
using namespace std::chrono;
using hrc = std::chrono::high_resolution_clock;
template<class T>
void f(
T& s,
unsigned const NN,
unsigned const RR
) noexcept {
auto t = hrc::now();
for (unsigned x = 0; x < RR; ++x) {
bool const b = s[x % NN];
(void)b;
s[x % NN] = true;
}
std::cout
<< duration_cast<milliseconds>(hrc::now() - t).count()
<< " ms\n"
;
}
signed
main() {
static unsigned const
N = 5e6,
R = 3e7
;
std::bitset<N> bs;
f(bs, N, R);
std::vector<bool> v(N);
f(v, N, R);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment