SE250:lab-3:klod004

From Marks Wiki
Jump to navigation Jump to search

Lab 3 Report This lab was about finding out the time taken to to store elements in an array list, whose size could be varied. Task one was to calculate time taken to store elements into the array. This was formulated using a for loop. The code for the program was

#include <stdio.h>
#include "arraylist.h"

int main (){
	int time,i;
	ArrayList arr;
	arraylist_init(&arr);
	//ensure_capacity(&arr, 10000000);
	time = clock();
	for ( i = 0; i<3000000; i++){
		arraylist_push(&arr, 100);
	}
	time = clock()-time;
	printf("The time taken for the for loop to be excuted is %d milliseconds\n", time);
}

With variations to the limit of i, and the push method was changed to put in the last task. The results for task 1 are, for i<1000000 - 157 milliseconds for i<10000000 - 1508 milliseconds This shows a direct relationship between the limit of i and the time taken.

Task 2 was to repeat the same code but changing the growth rate in the put fucntion. This did not give much difference. So the rate was about the same.

Task 3 was to change the ARRAYLIST_MIN_ALLOC variable in the arraylist.c file. Changing this fucntion yielded no changes in time taken to store the variables.

Task 4, changing the ensure_capacity from before didnt give too much of a difference to the results, the results were similar to task 1.

Task 5 was to change the growth rate of the array from x2 to +1000, from a product to an increment. The results for this was found to be

for i<1000000 - 3157 Milliseconds

for i<2000000 - 12344 Milliseconds

for i<3000000 - 27984 Milliseconds

for i<9000000 - 244006 Milliseconds


Task 6 The push function was just changed to put function. The difference was noticable as there was only one call to a function made, as in, when the push function was used, it called the put function from the push function, so this way, it is more economical, and faster. The results are

i<1000000 - 85

i<10000000- 958

i<100000000-9335

It was found from this lab that it is easier to call one method and saves time as well, instead of calling a method from another, ad also it is much faster for arrays to grow in an exponantial way than a linear way. Multiplication rather than addition. As for addition, it was noticed that the relationship was forming an exponantial curve, the time taken for calculations was getting bigger and bigger as the number of i was increased by minor factors.