-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
61 lines (50 loc) · 1.54 KB
/
main.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
/*
* File: main.c
* Author: Michael_Meding
*
* Created on September 16, 2013, 2:11 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define LISTSIZE 1000000
#define MIDPOINT LISTSIZE/2
/*
*
*/
int main(int argc, char** argv) {
srand(time(NULL)); // initalize random number generator with current time as the seed value;
int random = rand() % 1000000; // generate random number between 0 - 1000000
clock_t startTime = clock();
// populate list
int x = 0;
for (x = 0; x < LISTSIZE; x++) {
l_insert(random); // insert into list
random = rand() % 1000000; // generate new random number between 0 - 1000000
}
// time taken to check head value
double time_taken = l_check(1);
if (time_taken == 0) {
printf("time taken to find value = ~1 nanosecond\n");
} else {
printf("time taken to find value = %f seconds\n", time_taken);
}
// time taken to check the midpoint value
time_taken = l_check(MIDPOINT);
if (time_taken == 0) {
printf("time taken to find value = ~1 nanosecond\n");
} else {
printf("time taken to find value = %f seconds\n", time_taken);
}
// time taken to check the endpoint value
time_taken = l_check(LISTSIZE);
if (time_taken == 0) {
printf("time taken to find value = ~1 nanosecond\n");
} else {
printf("time taken to find value = %f seconds\n", time_taken);
}
clock_t endTime = clock();
double cpu_time = (double) (endTime - startTime) / CLOCKS_PER_SEC;
printf("\ntotal cpu time = %f sec\n", cpu_time);
return (EXIT_SUCCESS);
}