SE250:lab-3:sbha077

From Marks Wiki
Revision as of 05:19, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (12 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Lab 3 Report

Task 1

We had to calculate the time taken to insert n elements into an array (ArrayList) using the arraylist_push function.

CODE >>

#include "arraylist.c"
#include <time.h>

int main() {

	ArrayList myArr;

	int n = 12345678;

	clock_t start, stop;

	int i;
	double elapsed;

	arraylist_init(&myArr);

	start = clock();

	for (i = 0; i<n; i++) {

		arraylist_push(&myArr, 2);

	}

	stop = clock();

	elapsed = ((double) (stop - start)) / CLOCKS_PER_SEC;

	printf("\n Time taken for %d pushes = %lf\n", n, elapsed);

	return 0;

}

RESULTS >>

Trial 1 : Time taken for 12345678 pushes = 0.468000 seconds
Trial 2 : Time taken for 12345678 pushes = 0.468000 seconds
Trial 3 : Time taken for 12345678 pushes = 0.468000 seconds
Trial 4 : Time taken for 12345678 pushes = 0.484000 seconds
Trial 5 : Time taken for 12345678 pushes = 0.515000 seconds

OBSERVATION >>

It takes about 0.5 odd seconds on my laptop for 12345678 pushes.

Task 2

RESULTS >>

Trial 1 ( * 3.0 ) : Time taken for 12345678 pushes = 0.453000 seconds
Trial 2 ( * 4.0 ) : Time taken for 12345678 pushes = 0.421000 seconds
Trial 3 ( * 5.0 ) : Time taken for 12345678 pushes = 0.421000 seconds
Trial 4 ( * 10.0 ): Time taken for 12345678 pushes = 0.390000 seconds
Trial 5 ( * 100.0): Time taken for 12345678 pushes = 0.390000 seconds

OBSERVATION >>

Not a major difference in time observed here.

Task 3

RESULTS >>

Trial 1 (ARRAYLIST_MIN_ALLOC = 100)     : Time taken for 123456789 pushes = 4.906000 seconds
Trial 2 (ARRAYLIST_MIN_ALLOC = 1000)    : Time taken for 123456789 pushes = 4.531000 seconds
Trial 3 (ARRAYLIST_MIN_ALLOC = 10000)   : Time taken for 123456789 pushes = 4.812000 seconds
Trial 4 (ARRAYLIST_MIN_ALLOC = 100000)  : Time taken for 123456789 pushes = 4.968000 seconds
Trial 5 (ARRAYLIST_MIN_ALLOC = 1000000) : Time taken for 123456789 pushes = 4.546000 seconds

OBSERVATION >>

Interestingly, there really isn't much of a time change. Infact unless we get pedantic with our times, there really isn't any noticable difference in time.


Task 4

RESULTS >>

Trial 1 (preallocated space = 10)       : Time taken for 123456789 pushes = 0.390000 seconds
Trial 2 (preallocated space = 100)      : Time taken for 123456789 pushes = 0.390000 seconds
Trial 3 (preallocated space = 1000)     : Time taken for 123456789 pushes = 0.375000 seconds
Trial 4 (preallocated space = 10000)    : Time taken for 123456789 pushes = 0.375000 seconds
Trial 5 (preallocated space = 10000000) : Time taken for 123456789 pushes = 0.390000 seconds

OBSERVATION >>

Again, no noticable time difference experienced; they are rather consistent.


Task 5

RESULTS >>


Task 6

RESULTS >>