-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.cpp
41 lines (35 loc) · 1021 Bytes
/
simple.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N_SIZE 3200000
#define ITERATION 12
#define Q 28
int main(int argc, char* argv[]) {
int i, j, count;
double sum, total_time = 0;
double* a = new double[N_SIZE];
double* b = new double[N_SIZE];
double* c = new double[N_SIZE];
for (i = 0; i < N_SIZE; ++i) {
a[i] = 1;
b[i] = 1;
}
clock_t start_time, end_time;
// Последовательное суммирование
for (count = 0; count < ITERATION; count++) {
start_time = clock();
for (i = 0; i < N_SIZE; i++) {
for (j = 0; j < Q; ++j) {
c[i] = a[i] + b[i];
}
}
end_time = clock();
end_time = end_time - start_time;
total_time += end_time;
}
sum = sum / (ITERATION * Q);
printf("\nConsistent Q: %d", Q);
printf("\nTotal Sum = %10.2f", sum);
printf("\nTIME OF WORK IS %f ", total_time / CLOCKS_PER_SEC / ITERATION);
return 0;
}