-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eric Zhuang
authored and
Eric Zhuang
committed
Oct 14, 2016
1 parent
8fa0ad1
commit 18b44e9
Showing
3 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
COMPILER = gcc | ||
CFLAGS = -Wall -g | ||
CFLAGS2 = -g | ||
|
||
all: mymalloc Test1 Test2 Test3 Test4 Test5 Test6 Test7 Test8 | ||
.PHONY: all | ||
.PHONY: clean | ||
|
||
mymalloc.o: mymalloc.c mymalloc.h | ||
$(COMPILER) $(CFLAGS) -c mymalloc.c | ||
|
||
main.o: main.c mymalloc.h | ||
$(COMPILER) $(CFLAGS2) -c main.c | ||
|
||
mymalloc: mymalloc.o main.o | ||
$(COMPILER) $(CFLAGS) -o mymalloc main.o mymalloc.o | ||
|
||
|
||
Test1.o: Test1.c | ||
$(COMPILER) $(CFLAGS2) -c Test1.c | ||
|
||
Test1: mymalloc.o Test1.o | ||
$(COMPILER) $(CFLAGS) -o Test1 Test1.o mymalloc.o | ||
|
||
|
||
Test2.o: Test2.c | ||
$(COMPILER) $(CFLAGS2) -c Test2.c | ||
|
||
Test2: mymalloc.o Test2.o | ||
$(COMPILER) $(CFLAGS) -o Test2 Test2.o mymalloc.o | ||
|
||
|
||
Test3.o: Test3.c | ||
$(COMPILER) $(CFLAGS2) -c Test3.c | ||
|
||
Test3: mymalloc.o Test3.o | ||
$(COMPILER) $(CFLAGS) -o Test3 Test3.o mymalloc.o | ||
|
||
|
||
Test4.o: Test4.c | ||
$(COMPILER) $(CFLAGS2) -c Test4.c | ||
|
||
Test4: mymalloc.o Test4.o | ||
$(COMPILER) $(CFLAGS) -o Test4 Test4.o mymalloc.o | ||
|
||
|
||
Test5.o: Test5.c | ||
$(COMPILER) $(CFLAGS2) -c Test5.c | ||
|
||
Test5: mymalloc.o Test5.o | ||
$(COMPILER) $(CFLAGS) -o Test5 Test5.o mymalloc.o | ||
|
||
|
||
Test6.o: Test6.c | ||
$(COMPILER) $(CFLAGS2) -c Test6.c | ||
|
||
Test6: mymalloc.o Test6.o | ||
$(COMPILER) $(CFLAGS) -o Test6 Test6.o mymalloc.o | ||
|
||
|
||
Test7.o: Test7.c | ||
$(COMPILER) $(CFLAGS2) -c Test7.c | ||
|
||
Test7: mymalloc.o Test7.o | ||
$(COMPILER) $(CFLAGS) -o Test7 Test7.o mymalloc.o | ||
|
||
|
||
Test8.o: Test8.c | ||
$(COMPILER) $(CFLAGS2) -c Test8.c | ||
|
||
Test8: mymalloc.o Test7.o | ||
$(COMPILER) $(CFLAGS) -o Test8 Test8.o mymalloc.o | ||
|
||
|
||
clean: | ||
rm -f *.o mymalloc Test1 Test2 Test3 Test4 Test5 Test6 Test7 Test8 | ||
|
||
CC = gcc | ||
CCFLAGS = -Wall -g | ||
|
||
all: runfile | ||
|
||
runfile: mymalloc.o memgrind.o | ||
$(CC) $(CCFLAGS) -o runfile mymalloc.o memgrind.o | ||
|
||
mymalloc.o: mymalloc.c mymalloc.h | ||
$(CC) $(CCFLAGS) -c mymalloc.c | ||
|
||
memgrind.o: memgrind.c | ||
$(CC) $(CCFLAGS) -c memgrind.c | ||
|
||
clean: | ||
rm -f runfile mymalloc.o memgrind.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include <stdio.h> | ||
#include <sys/time.h> | ||
#include "mymalloc.h" | ||
|
||
|
||
void testA(){ | ||
char* malloc_pointers[3000]; | ||
int pointer_counter = 0; | ||
int workload_counter = 0; | ||
long int time_total = 0; | ||
|
||
while(workload_counter < 100) { | ||
struct timeval start, end; | ||
gettimeofday(&start, NULL); | ||
|
||
|
||
while(pointer_counter < 3000) { | ||
|
||
malloc_pointers[pointer_counter] = malloc(1); | ||
pointer_counter++; | ||
|
||
} | ||
pointer_counter = 0; | ||
while(pointer_counter < 3000) { | ||
|
||
free(malloc_pointers[pointer_counter]); | ||
pointer_counter++; | ||
|
||
} | ||
gettimeofday(&end, NULL); | ||
time_total = time_total + ((end.tv_sec * 1000000 + end.tv_usec) | ||
- (start.tv_sec * 1000000 + start.tv_usec)); | ||
workload_counter++; | ||
} | ||
long int average_time = time_total/100; | ||
printf("Average Time for Test A was %ld microseconds\n", average_time); | ||
} | ||
|
||
void testB(){ | ||
int pointer_counter = 0; | ||
int workload_counter = 0; | ||
long int time_total = 0; | ||
|
||
while(workload_counter < 100) { | ||
struct timeval start, end; | ||
gettimeofday(&start, NULL); | ||
|
||
|
||
while(pointer_counter < 3000) { | ||
|
||
char* test_pointer = (char*)malloc(1); | ||
free(test_pointer); | ||
pointer_counter++; | ||
} | ||
|
||
gettimeofday(&end, NULL); | ||
time_total = time_total + ((end.tv_sec * 1000000 + end.tv_usec) | ||
- (start.tv_sec * 1000000 + start.tv_usec)); | ||
workload_counter++; | ||
} | ||
long int average_time = time_total/100; | ||
printf("Average Time for Test B was %ld microseconds\n", average_time); | ||
|
||
} | ||
|
||
void testC(){ | ||
|
||
int malloc_counter = 0; | ||
int free_counter = 0; | ||
int total_counter = 0; | ||
time_t t; | ||
|
||
/* Intializes random number generator */ | ||
srand((unsigned) time(&t)); | ||
|
||
while(total_counter < 6000) { | ||
|
||
int random_number = rand() % 2; | ||
if(random_number == 0 && malloc_counter < 3000) { | ||
malloc_counter++; | ||
total_counter++; | ||
}else if (random_number == 1 && free_counter < 3000) { | ||
free_counter++; | ||
total_counter++; | ||
} | ||
|
||
} | ||
printf("total_counter is: %d\nmalloc_counter is: %d\nfree_counter is: %d\n",total_counter,malloc_counter,free_counter); | ||
|
||
} | ||
void testD(){ | ||
|
||
} | ||
|
||
void testEF(){ | ||
|
||
} | ||
|
||
|
||
int main( int argc, char** argv ) { | ||
block_init(); | ||
testA(); | ||
testB(); | ||
testC(); | ||
|
||
return 0; | ||
} | ||
Contact GitHub API Training Shop Blog About | ||
© 2016 GitHub, Inc. Terms Privacy Security Status Help |