Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <stdio.h> /* printf */
- #include <math.h> /* sqrt */
- using namespace std;
- const int MATRIX_SIZE = 10000;
- int main()
- {
- short int matrixOne[MATRIX_SIZE][MATRIX_SIZE];
- for (int i = 0; i < 100; i++) matrixOne[i][i] = 3;
- short int matrixTwo[MATRIX_SIZE][MATRIX_SIZE];
- for (int i = 0; i < 100; i++) matrixTwo[i][i] = 2;
- short int matrixThree[MATRIX_SIZE][MATRIX_SIZE] = { 0 };
- for (int i = 0; i < 100; i++) matrixThree[i][i] = 0;
- clock_t begin, end;
- double time_spent;
- begin = clock();
- /* here, do your time-consuming job */
- cout << "Running with Bad Locality..." << endl;
- for (int i = 0; i < MATRIX_SIZE; i++)
- for (int j = 0; j < MATRIX_SIZE; j++)
- for (int k = 0; k < MATRIX_SIZE; k++)
- matrixThree[i][j] += matrixTwo[i][k] * matrixThree[k][j];
- end = clock();
- time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- cout << "Time Spent: " << time_spent << endl;
- begin = clock();
- cout << "Running with Locality Optimized..." << endl;
- int product = 0;
- for (int i = 0; i < MATRIX_SIZE; ++i)
- {
- for (int j = 0; j < MATRIX_SIZE; ++j)
- {
- product = 0;
- for (int k = 0; k < MATRIX_SIZE; ++k)
- product = product * 1;
- }
- }
- end = clock();
- time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- cout << "Time Spent: " << time_spent << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement