Created
May 28, 2014 11:47
-
-
Save ncordon/d84b11b10004f676668a to your computer and use it in GitHub Desktop.
Struct secuencial
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 <functional> | |
#include <numeric> | |
#include <omp.h> | |
#include <algorithm> | |
#include <iostream> | |
#include <sstream> | |
#include <vector> | |
#include <chrono> | |
#include <random> | |
const int N = 5000, REP = 4000; | |
std::default_random_engine generator(N * REP); | |
std::uniform_int_distribution<int> distribution(0, 9); | |
auto rng = std::bind(distribution, generator); | |
struct S { | |
int a, b; | |
S(): a(rng()), b(rng()) {} | |
} s[N]; | |
int main(){ | |
int R[REP]; | |
auto start = std::chrono::high_resolution_clock::now(); | |
for (int ii = 0; ii < REP; ++ii){ | |
int X1, X2; | |
for (int i = 0; i < N; ++i) | |
X1 = 2 * s[i].a + ii; | |
for (int i = 0; i < N; i++) | |
X2 = 3 * s[i].b - ii; | |
if (X1 < X2) | |
R[ii] = X1; | |
else | |
R[ii] = X2; | |
} | |
auto stop = std::chrono::high_resolution_clock::now(); | |
std::cout << "tiempo: " << | |
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - | |
start).count() << std::endl; | |
return std::accumulate(R, R + REP, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment