Created
October 24, 2020 12:52
-
-
Save ranisalt/68fb53d16b118ffad1879efb3bd0eed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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