SE250:lab-3:llay008

From Marks Wiki
Jump to navigation Jump to search

TASK ONE

The first task was quite straightforward but it took me a while to get going. I read each of the functions and tried to understand what they did. I used the init_arraylist function to initialise the array and then called the clock function outside a for loop, inside which arraylist_push was called n number of times to insert the number 10 into the array. t1 was subtracted from t0 and printed at the bottom.

Results 

n              time
1000000        46
10000000       420
100000000      4259   *here I first noticed a significant time lag*
1000000000     this produced the error:
               "assertion "alist->arr != (element_t*)0" failed: file "arraylist.c", line 39"

The code came up with many errors the first time I compiled it, but these were mainly small mistakes in my code. There was one strange error that I could not get rid of. I later discovered that this was because I needed to compile "arraylist.c" before I ran my own code. At the time I corrected this error by pasting my code at the bottom of "arraylist.c" After I corrected it I still came up with errors. This was because emacs was running the wrong compiler. After I had help correcting this my program finally ran error free.

Note for the future: To change compiler: Options/Customize Emacs/Specific Options... Type at the bottom: shell-file-name Change Shell File Name to C:/cygwin/bin/bash.exe


TASK TWO

Keeping n as 10000000 (similar to case 2 in the above example) I changed the "*2" in "arraylist_put".

Results

*n    time
4     327      
8     358
16    327
32    328
64    this produced the error:
      assertion "alist->arr != (element_t*)0" failed: file "arraylist.c", line 39
      5764 Hangup                  ./arraylist.exe

These results were all around the same value, which was not what I expected. The time taken did not increase with size that the array was increased by.

Next I tried the same experiment, but only using small increments.

Results

*n    time
1.1     952      
1.3     562
1.5     483
1.7     436
1.9     390
2.0     405
2.5     373

There is pattern to the results. The closer "*n" is to 1 the longer the program takes.

TASK THREE

This task is again very straightforward.

ARRAYLIST_MIN_ALLOC   time
16             405     *from previous example*
2              452
8              421
32             452
100            390
10000          373
100000000      327

The trend indicated by these results is that the time decreases with the length of the array. The difference, though, is so small as to be insignificant. I had to increase ARRAYLIST_MIN_ALLOC by a considerable amount before I got a noticible difference.

TASK FOUR

I inserted the function "ensure_capacity" and ran the code, repeating experiment 1

Results 

n              time         time from task one
1000000        31           46
10000000       343          420       
100000000      3370         4259      
1000000000     error        error

As can be seen by the results, using "ensure_capacity" decreases the compiling time.

TASK FIVE

This task involves changing "*n" to an incremental value such as "+ n".

+ n            time
10             ?         *this took ages to compile, so I stopped it prematurely*
100            46
1000           31
5000           46
10000          30
100000         46
100000000      46

There is no difference in compile time when you increment n, provided the n is over a particular number (in which case it takes forever to compile).

I realised as I started Task Six that I had left ARRAYLIST_MIN_ALLOC as 1000000000 (or something like it) for Tasks Four and Five. I changed it back to 16.

TASK SIX

This task involced using "ararylist_put" to put elements at the beginning of the array.

n              time                 time from task one
10000          31                   -
100000         4625                 -
1000000        *took too long*      46
10000000       *took too long*      420       
100000000      *did not try*        4259      
1000000000     *did not try*        error

As is evidenced by these results, this takes *considerably* longer. The smallest value of n from the first task, in task six took so long to process that I gave up on it. This is *not* an effective way of adding data and should be avoided.

Overall, this lab was easy to implement, but some of the results were interesting, particularly those of task six.


Screencast

user:llay008