Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Written by Bill Punch
#include<iostream>
using std::cout; using std::endl; using std::boolalpha;
#include<chrono>
#include<iomanip>
#include<bitset>
using std::bitset;
int main() {
const size_t sz = 100000;
const int iter = 1000;
cout << boolalpha << std::fixed << std::setprecision(5);
int val;
long av_time = 0;
std::bitset<sz> v(0);
std::bitset<sz> tmp(0);
v[sz/2] = 1;
using time_unit = std::chrono::microseconds;
//using time_unit = std::chrono::milliseconds;
for(int run = 0; run < 10; run++){
auto start = std::chrono::steady_clock::now();
for(int i=0; i<iter; ++i){
for(size_t i = v.size(); i>=1; --i){
val = (int)v[i-1] << 2 | (int)v[i] << 1 | (int)v[i+1];
tmp[i] = (val == 3 || val == 5 || val == 6);
}
v = tmp;
}
auto duration = std::chrono::duration_cast<time_unit>(std::chrono::steady_clock::now() - start);
av_time += duration.count();
}
cout << "msec = " << av_time/10.0 << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment