<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asrag014</id>
	<title>SE250:lab-3:srag014 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asrag014"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:srag014&amp;action=history"/>
	<updated>2026-04-15T16:44:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-3:srag014&amp;diff=5836&amp;oldid=prev</id>
		<title>Mark: 22 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:srag014&amp;diff=5836&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:29Z</updated>

		<summary type="html">&lt;p&gt;22 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===Task 1===&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 #include &amp;quot;arraylist.h&amp;quot;&lt;br /&gt;
 int main(){&lt;br /&gt;
 double time_period;&lt;br /&gt;
 int x;  &lt;br /&gt;
 ArrayList arr; &lt;br /&gt;
 clock_t begin;&lt;br /&gt;
 clock_t end;&lt;br /&gt;
 arraylist_init(&amp;amp;arr);&lt;br /&gt;
 begin = clock();&lt;br /&gt;
 for (x = 0; x &amp;lt; 10000000; x++) {&lt;br /&gt;
 arraylist_push(&amp;amp;arr,4);&lt;br /&gt;
 }&lt;br /&gt;
 end = clock();&lt;br /&gt;
 time_period = ((double) (end- begin)) / CLOCKS_PER_SEC;&lt;br /&gt;
 printf(&amp;quot;Time taken to push 10000000 into the array took %lf seconds\n&amp;quot;, time_period);&lt;br /&gt;
 }&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output of the code was:&lt;br /&gt;
&lt;br /&gt;
 Time taken to push 10000000 into the array took 1.548000 seconds&lt;br /&gt;
&lt;br /&gt;
===Task 2===&lt;br /&gt;
The objective of this task is to change the growth factor to any thing other than the default value (default is *2) and to see how/if the results change.&lt;br /&gt;
&lt;br /&gt;
When growth factor was increased to:&lt;br /&gt;
&lt;br /&gt;
* 3, Time taken to push 10000000 into the array took 1.548000 seconds&lt;br /&gt;
&lt;br /&gt;
* 5, Time taken to push 10000000 into the array took 1.580000 seconds&lt;br /&gt;
&lt;br /&gt;
* 7, Time taken to push 10000000 into the array took 1.424000 seconds&lt;br /&gt;
&lt;br /&gt;
* 1.20, Time taken to push 10000000 into the array took 2.093000 seconds &lt;br /&gt;
&lt;br /&gt;
* 1.01, Progaram crashes!&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From the results I got it seems as if there is only a marginal difference as the growth factor is increased.&lt;br /&gt;
As the growth factor nears 1 though the time taken to compute the programme increases, and at 1.01 growth factor the program crashes which is understandable as the number is too big for the memory capacity.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Task 3===&lt;br /&gt;
Restoring the original growth factor (ie.2.0) and  repeating the experiment with&lt;br /&gt;
a variety of initial array sizes produces the following times:&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 1000000, Time taken to push 10000000 into the array took 1.570000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 100000, Time taken to push 10000000 into the array took 1.498000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 10000, Time taken to push 10000000 into the array took 1.474000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 1000, Time taken to push 10000000 into the array took 1.511000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 100, Time taken to push 10000000 into the array took 1.628000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 10,Time taken to push 10000000 into the array took 1.827000 seconds&lt;br /&gt;
*ARRAYLIST_MIN_ALLOC 1,Time taken to push 10000000 into the array took 2.023000  seconds&lt;br /&gt;
&lt;br /&gt;
From those results it seems the general trend is that time increases as ARRAYLIST_MIN_ALLOC is increased.&lt;br /&gt;
&lt;br /&gt;
===Task 4===&lt;br /&gt;
By adding the line:&lt;br /&gt;
&lt;br /&gt;
 ensure_capacity(&amp;amp;arr,10000000 );&lt;br /&gt;
&lt;br /&gt;
The output derived after this modification is:&lt;br /&gt;
&lt;br /&gt;
 Time taken to push 10000000 into the array took 1.355000 seconds&lt;br /&gt;
&lt;br /&gt;
There is a marked time difference between the preallocated one and the other one.&lt;br /&gt;
&lt;br /&gt;
===Task 5===&lt;br /&gt;
I tried this both with the ensure_capacity line of code and without it.&lt;br /&gt;
&lt;br /&gt;
Whithout the ensure_capacity line of code, the program took ages to compute, so had to bring down the iterations to 1000000,the&lt;br /&gt;
output I derived from this was :&lt;br /&gt;
&lt;br /&gt;
 Time taken to push 10000000 into the array took 3.219000 seconds&lt;br /&gt;
&lt;br /&gt;
With the ensure_capacity line of code, the time I derived for 10000000 (default) was:&lt;br /&gt;
&lt;br /&gt;
 Time taken to push 10000000 into the array took 1.328 seconds&lt;br /&gt;
&lt;br /&gt;
===Task 6===&lt;br /&gt;
In this task, the objective is to use array_put instead of array_push.&lt;br /&gt;
When I used the array_put, my program compiles but it takes forever to display the output.&lt;br /&gt;
So basically the lesson I think we were meant to get from this task is that adding elements to the back of the list is faster than adding elements to the front of the list.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>