-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (43 loc) · 1.01 KB
/
main.cpp
File metadata and controls
47 lines (43 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <chrono>
#define MATRIX_SIZE 31000
using namespace std;
class Timer
{
public:
Timer()
: start_(std::chrono::high_resolution_clock::now())
{
}
~Timer()
{
const auto finish = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(finish - start_).count() << " us" << std::endl;
}
private:
const std::chrono::high_resolution_clock::time_point start_;
};
int main()
{
int* matrix = new int [MATRIX_SIZE*MATRIX_SIZE];
for (int i=0; i<MATRIX_SIZE; i++){
for (int j=0; j<MATRIX_SIZE; j++) matrix[i*MATRIX_SIZE+j]=i*MATRIX_SIZE+j;
}
{
Timer T1;
long int sum1=0;
for (int i=0; i<MATRIX_SIZE; i++){
for (int j=0; j<MATRIX_SIZE; j++) sum1+=matrix[i*MATRIX_SIZE+j];
}
cout<<sum1<<endl;
}
{
Timer T2;
long int sum2=0;
for (int i=0; i<MATRIX_SIZE; i++){
for (int j=0; j<MATRIX_SIZE; j++) sum2+=matrix[j*MATRIX_SIZE+i];
}
cout<<sum2<<endl;
}
return 0;
}