Created
March 16, 2016 20:19
-
-
Save boxdot/b70aca82b5ce665d3906 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
#include <array> | |
#include <iostream> | |
#include <stdio.h> | |
#include <chrono> | |
enum class Ax { X = 0, Y = 1, Z = 2 }; | |
static constexpr std::array<Ax, 3> AXES = {Ax::X, Ax::Y, Ax::Z}; | |
static constexpr auto COUNT = 200000000; | |
void experiment1() { | |
int res = 0; | |
auto start = std::chrono::steady_clock::now(); | |
for (size_t i = 0; i < COUNT; ++i) { | |
for (auto ax : AXES) { | |
res += static_cast<int>(i); | |
} | |
} | |
auto end = std::chrono::steady_clock::now(); | |
std::cerr | |
<< std::chrono::duration_cast<std::chrono::milliseconds>( | |
end - start).count() << std::endl; | |
} | |
void experiment2() { | |
int res = 0; | |
auto start = std::chrono::steady_clock::now(); | |
for (size_t i = 0; i < COUNT; ++i) { | |
for (int j = 0; j < 3; ++j) { | |
res += j; | |
} | |
} | |
auto end = std::chrono::steady_clock::now(); | |
std::cerr | |
<< std::chrono::duration_cast<std::chrono::milliseconds>( | |
end - start).count() << std::endl; | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
experiment1(); | |
experiment2(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment