forked from mkem114/COMPSYS-304-Assignment-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment.c
83 lines (60 loc) · 1.76 KB
/
assignment.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* do not add other includes */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
double getTime() {
struct timeval t;
double sec, msec;
while (gettimeofday(&t, NULL) != 0);
sec = t.tv_sec;
msec = t.tv_usec;
sec = sec + msec / 1000000.0;
return sec;
}
/* for task 1 only */
void usage(void) {
fprintf(stderr, "Usage: cachetest1/2 [--repetitions M] [--array_size N]\n");
exit(1);
}
int main(int argc, char *argv[]) {
double t1, t2;
/* variables for task 1 */
unsigned int M = 1000;
unsigned int N = 256 * 1024;
unsigned int i;
/* declare variables; examples, adjust for task */
//int *a;
double a[100];
/* parameter parsing task 1 */
for (i = 1; i < (unsigned) argc; i++) {
if (strcmp(argv[i], "--repetitions") == 0) {
i++;
if (i < argc)
sscanf(argv[i], "%u", &M);
else
usage();
} else if (strcmp(argv[i], "--array_size") == 0) {
i++;
if (i < argc)
sscanf(argv[i], "%u", &N);
else
usage();
} else usage();
}
/* allocate memory for arrays; examples, adjust for task */
//a = malloc (N * sizeof(int));
/* initialise arrray elements */
t1 = getTime();
/* code to be measured goes here */
/***************************************/
/***************************************/
t2 = getTime();
/* output; examples, adjust for task */
printf("time: %6.2f secs\n", (t2 - t1));
/* IMPORTANT: also print the result of the code, e.g. the sum,
* otherwise compiler might optimise away the code */
/* free memory; examples, adjust for task */
//free(a);
return 0;
}