-
-
Save cwvh/10f242628b199163fc1c 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 <iostream> | |
#include <chrono> | |
#include <cstdlib> | |
int main() { | |
const int N = 7*1024; | |
int** m = new int*[N]; | |
int* n = new int[N*N]; | |
int* k = new int[N*N]; | |
for (int i = 0; i < N; i++) { | |
m[i] = new int[N]; | |
for (int j = 0; j < N; j++) { | |
const int r = arc4random(); | |
m[i][j] = r; | |
n[i*N + j] = r; | |
k[i*N + j] = r; | |
} | |
} | |
using namespace std::chrono; | |
time_point<system_clock> start, end; | |
int elapsed; | |
start = system_clock::now(); | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
m[i][j] += 42; | |
} | |
} | |
end = system_clock::now(); | |
elapsed = duration_cast<milliseconds>(end - start).count(); | |
std::cout << elapsed << " ms\n"; | |
start = system_clock::now(); | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
n[j*N + i] += 42; | |
} | |
} | |
end = system_clock::now(); | |
elapsed = duration_cast<milliseconds>(end - start).count(); | |
std::cout << elapsed << " ms\n"; | |
start = system_clock::now(); | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
k[i*N + j] += 42; | |
} | |
} | |
end = system_clock::now(); | |
elapsed = duration_cast<milliseconds>(end - start).count(); | |
std::cout << elapsed << " ms\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment