-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_testcase1.c
More file actions
executable file
·38 lines (32 loc) · 1 KB
/
advanced_testcase1.c
File metadata and controls
executable file
·38 lines (32 loc) · 1 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
#include <stdio.h>
#include <stdlib.h>
#include "537malloc.h"
#include <time.h>
#define LIMIT 1000000
#define SIZE 1
int main() {
char *ptr[LIMIT];
int i = 0;
clock_t startTimeAlloc = clock();
for(i = 0; i < LIMIT; i++) {
ptr[i] = malloc537(SIZE);
printf("Allocated 1 byte of memory at %p\n", ptr[i]);
}
clock_t endTimeAlloc = clock();
clock_t startTimeMemCheck = clock();
for(i = 0; i < LIMIT; i++) {
printf("Mem check : %p\n", ptr[i]);
memcheck537(ptr[i], 1);
}
clock_t endTimeMemCheck = clock();
clock_t startTimeFree = clock();
for(i = 0; i < LIMIT; i++) {
printf("Freeing : %p\n", ptr[i]);
free537(ptr[i]);
}
clock_t endTimeFree = clock();
printf("If this prints, you get points!\n");
printf("Alloc Time Taken : %f secs\n", ((double)endTimeAlloc - startTimeAlloc) / CLOCKS_PER_SEC);
printf("Memcheck Time Taken : %f secs\n", ((double)endTimeMemCheck - startTimeMemCheck) / CLOCKS_PER_SEC);
printf("Free Time Taken : %f secs\n", ((double)endTimeFree - startTimeFree) / CLOCKS_PER_SEC);
}