-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
54 lines (42 loc) · 1.19 KB
/
main.c
File metadata and controls
54 lines (42 loc) · 1.19 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
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "datatype.h"
// #define SA 1
void main()
{
datatype * array1 = calloc(ARRAY_SIZE, sizeof(datatype));
datatype * array2 = calloc(ARRAY_SIZE, sizeof(datatype));
#ifdef SA
int * tmpArray = calloc(ARRAY_SIZE, sizeof(int));
#endif
//fill array1 with data
for(int i = 0; i < ARRAY_SIZE; i++)
{
array1[i].data = ARRAY_SIZE-i;
}
float startTime = (float)clock()/CLOCKS_PER_SEC;
#ifdef SA
//copy over data to small array
for(int i = 0; i < ARRAY_SIZE; i++)
{
tmpArray[i] = array1[i].data;
}
//copy over data from small array to big array
for(int i = 0; i < ARRAY_SIZE; i++)
{
array2[i].data = tmpArray[i];
}
#else
//copy over data
for(int i = 0; i < ARRAY_SIZE; i++)
{
array2[i].data = array1[i].data;
}
#endif
float endTime = (float)clock()/CLOCKS_PER_SEC;
printf("time elapsed %f\n", endTime - startTime);
srand ( time(NULL) );
int index = rand() % ARRAY_SIZE;
printf("array entry[%i]: %i\n", index, array2[index].data);
}