Last active
January 13, 2018 20:37
-
-
Save DavidButts/5d9d948e18acdf5206b61af6119b7cee to your computer and use it in GitHub Desktop.
This file contains 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
//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