SE250:lab-3:dsan039

From Marks Wiki
Jump to navigation Jump to search

Task One

Results

time taken for 1000000 elements to be inserted into array: 0.062000
time taken for 10 elements to be inserted into array: 0.000000
time taken for 500000 elements to be inserted into array: 0.031000

As you can see the time it takes to make 1 million additions to the array is double the time it takes to add half a million. any number smaller than about one hundred thousand will return a time which is too small to be displayed in only 6dp. This seems reasonable. These integer values are being added to the front of the array and so do not require the contents of the array to be moved with each addition. ~using gnu compiler with emacs.

Task two

Results

time taken for 100000000 elements to be inserted into array: 6.155000  (gf = 2x)
time taken for 100000000 elements to be inserted into array: 4.277000  (gf = 4x)

It is indicated that the time it takes for many elements to be added to an array can be decreased by increasing the growth factor - presumably because higher, then the array does not need to be made larger as many times, which means less function calls. The risk is using up too much memory and crashing the program prematurely.

task three

Results

time taken for 1000000 elements to be inserted into array: 0.062000 (50init)
time taken for 1000000 elements to be inserted into array: 0.063000 (10000init)
time taken for 1000000 elements to be inserted into array: 0.063000 (1000000init)
time taken for 1000000 elements to be inserted into array: 0.046000 (1000001init)
time taken for 1000000 elements to be inserted into array: 0.047000 (10000001init)

It seems the optimum starting size of the array is one million and 1, which is the number of elements taht need to be copied to the array. the performance begins to suffer for values less than this number and greater than is this number. The time it takes for the calculation understandably increases for starting sizes that are less than the space required (a larger initial size meaning fewer function calls to increase the size of the array).

Task Four

Results

  • (task one)
time taken for 1000000 elements to be inserted into array: 0.062000
time taken for 10 elements to be inserted into array: 0.000000
time taken for 500000 elements to be inserted into array: 0.031000
  • (task four)