SE250:lab-3:zyan057
Jump to navigation
Jump to search
Task 1
Code:
#include <stdio.h> #include <time.h> #include "arraylist.h" int main (void){ int i; ArrayList al; clock_t start; clock_t finish; clock_t time; arraylist_init( &al ); start = clock(); for (i = 0; i < 1000000; i++) { arraylist_push(&al, 1); } finish = clock(); time = finish - start; printf("%ld ticks", time); return 0; }
Results:
value for i time taken(ticks) 1000000 159 5000000 883 10000000 1607 50000000 7964 100000000 15816 500000000 error, out of memory
Task 2
Results:
growth factor time taken for n = 10000000 (ticks) 2 1607 3 1616 4 1674 5 1649 6 1698 10 1484 20 1885 30 1633
Above results showed that using n = 10000000 does not make much difference. So I tried using n = 100000000.
growth factor time taken for n = 100000000 (ticks) 2 16438 3 15972 4 15133 5 14709 6 14704 10 15145 20 error, out of memory
Still, does not make much diference.
Task 3
Results:
ARRAYLIST MIN ALLOC time taken for n = 100000000 (ticks) 16 16438 32 15646 64 15279 128 15933 256 15878 512 15315 1024 15912 2048 15315
Again, does not make much difference. I wonder if there is something wrong with my work...