SE250:lab-3:hals016

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

Lab3

Question 1

For question one I made a loop for the arralist_push function, to change the array value to zero, 10 million times. Here is my code.

int main() {
  ArrayList arra;
  int i;
  arraylist_init(&arra);
  int clock1,clock2;

  clock1 = clock();
  for(i=0;i<10000000;i++){
    arraylist_push(&arra, 0);
  }
  clock2=clock();
  printf("%d ms", (clock2-clock1));

  return 0;
}

The result ranged from 550-640ms.

Question 2

For question two I changed the growth factor to a variety of numbers.

'''OUTPUT'''

*3 Growth Factor - 
The for loop of 10 million loops took 594 ms.

*9^99999 GF - 
The for loop of 10 million loops took 531 ms.

*1 - Error -
/usr/bin/bash: line 1:  5576 Segmentation fault      (core dumped) ./arraylist2.exe.

*1.1 - 
The for loop of 10 million loops took 1204 ms.

*1.2 - 
The for loop of 10 million loops took 890 ms.

*1.3 - 
The for loop of 10 million loops took 750 ms.

*1.4 - 
The for loop of 10 million loops took 672 ms.

Question 3

For this question the starting allocation for the array needed to be changed to various numbers.

'''OUTPUT'''
''Original minimum allocation = 16''

Minimum Allocation of 1 - The for loop of 10 million loops took 562 ms.

Minimum Allocation of 100 - The for loop of 10 million loops took 594 ms.

Minimum Allocation of 99999 - The for loop of 10 million loops took 531 ms.

Minimum Allocation of 0.01 - /usr/bin/bash: line 1:  5576 Segmentation fault      (core dumped) ./arraylist3.exe.

The results suggest that the starting allocation does not affect the time it takes to do the loop 10 million times.

Question 4

Experiment 1 was repeated but with the added code of using the function "ensure_capacity" to allocate memory (initially) according to the number of loops in the for loop (10 million).

Partial Code

ensure_capacity(&arra,10000000);

The output was faster than normal.

'''OUTPUT'''
The for loop of 10 million loops took 437 ms.