Skip to content

Instantly share code, notes, and snippets.

@ranisalt
Created October 24, 2020 12:52
Show Gist options
  • Save ranisalt/68fb53d16b118ffad1879efb3bd0eed9 to your computer and use it in GitHub Desktop.
Save ranisalt/68fb53d16b118ffad1879efb3bd0eed9 to your computer and use it in GitHub Desktop.
#include <chrono>
#include <iostream>
#include <numeric>
int main() {
using namespace std;
using namespace std::chrono;
constexpr auto reps = numeric_limits<unsigned>::max() >> 1;
{
auto x = 1, counter = 0;
auto start = high_resolution_clock::now();
for (unsigned i = 0u; i < reps; ++i) {
if (x == 1)
++counter;
x = (x << 0) % 3;
}
auto end = high_resolution_clock::now();
std::cout << counter << "\t" << duration_cast<milliseconds>(end - start).count() << "ms\n";
}
{
auto x = 1, counter = 0;
auto start = high_resolution_clock::now();
for (unsigned i = 0u; i < reps; ++i) {
if (x == 1)
++counter;
x = (x << 1) % 3;
}
auto end = high_resolution_clock::now();
std::cout << counter << "\t" << duration_cast<milliseconds>(end - start).count() << "ms\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment