Skip to content

Instantly share code, notes, and snippets.

@DavidButts
Last active January 13, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidButts/5d9d948e18acdf5206b61af6119b7cee to your computer and use it in GitHub Desktop.
Save DavidButts/5d9d948e18acdf5206b61af6119b7cee to your computer and use it in GitHub Desktop.
//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