Last active
August 29, 2015 14:15
-
-
Save phg1024/cc744696bbbb93a673c5 to your computer and use it in GitHub Desktop.
effect of cache demonstration
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 <iostream> | |
| #include <time.h> | |
| #include <vector> | |
| using namespace std; | |
| int main(int argc, char **argv) { | |
| const int MAX = 10000; | |
| vector<vector<double>> A(MAX, vector<double>(MAX)); | |
| vector<double> x(MAX), y(MAX); | |
| for(int i=0;i<MAX;++i) | |
| for(int j=0;j<MAX;++j) A[i][j] = rand(); | |
| for(int i=0;i<MAX;++i) x[i] = rand(); | |
| clock_t ts, te; | |
| ts = clock(); | |
| for(int i=0;i<MAX;++i) { | |
| for(int j=0;j<MAX;++j) { | |
| y[i] += A[i][j] * x[j]; | |
| } | |
| } | |
| te = clock(); | |
| cout << te - ts << endl; | |
| ts = clock(); | |
| for(int j=0;j<MAX;++j) { | |
| for(int i=0;i<MAX;++i) { | |
| y[i] += A[i][j] * x[j]; | |
| } | |
| } | |
| te = clock(); | |
| cout << te - ts << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment