Last active
October 10, 2019 19:20
-
-
Save mitchute/d6969595d2b167a824479b5cc84df776 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 <algorithm> | |
#include <random> | |
#include <vector> | |
using namespace std; | |
using namespace std::chrono; | |
int main() { | |
// First create an instance of an engine. | |
random_device rnd_device; | |
// Specify the engine and distribution. | |
mt19937 mersenne_engine{rnd_device()}; // Generates random integers | |
uniform_int_distribution<int> dist{1, 10000}; | |
auto gen = [&dist, &mersenne_engine]() { | |
return static_cast<float>(dist(mersenne_engine)) / 10000; | |
}; | |
int numElements = 100000000; | |
vector<float> v1(numElements); | |
vector<float> v2(numElements); | |
generate(begin(v1), end(v1), gen); | |
generate(begin(v2), end(v2), gen); | |
vector<float> v3; | |
int i(0); | |
while (i < numElements) { | |
v3.emplace_back(v1[i] - v2[i]); | |
++i; | |
} | |
i = 0; | |
int dummy(0); | |
//// Uncomment/comment for IF/ELSE comparison //// | |
// while (i < numElements) { | |
// if (v3[i] >= 0) { | |
// ++dummy; | |
// } else { | |
// --dummy; | |
// } | |
// ++i; | |
// } | |
//// Uncomment/comment for std::signbit comparison //// | |
while (i < numElements) { | |
if (std::signbit(v3[i])) { | |
++dummy; | |
} else { | |
--dummy; | |
} | |
++i; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment