<?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%3Atlou006</id>
	<title>SE250:lab-3:tlou006 - 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%3Atlou006"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:tlou006&amp;action=history"/>
	<updated>2026-04-28T17:18:03Z</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:tlou006&amp;diff=5890&amp;oldid=prev</id>
		<title>Mark: 4 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:tlou006&amp;diff=5890&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:30Z</updated>

		<summary type="html">&lt;p&gt;4 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Q1 ==&lt;br /&gt;
Using the code&lt;br /&gt;
&lt;br /&gt;
 int main()&lt;br /&gt;
 {&lt;br /&gt;
  int i,j,t0;&lt;br /&gt;
  ArrayList alist;&lt;br /&gt;
  arraylist_init( &amp;amp;alist );&lt;br /&gt;
 &lt;br /&gt;
 for( j=0; j&amp;lt;10; j++ ) {&lt;br /&gt;
  t0 = clock();&lt;br /&gt;
  for( i=0; i&amp;lt;1000000; i++ ) {&lt;br /&gt;
   arraylist_push( &amp;amp;alist, 0 );&lt;br /&gt;
   }&lt;br /&gt;
  printf(&amp;quot;time taken : %d\n&amp;quot;, clock() - t0);&lt;br /&gt;
  arraylist_clear( &amp;amp;alist );&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
  arraylist_clear( &amp;amp;alist );&lt;br /&gt;
  return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
will hopefully give me the time taken to insert the number 0 one million times into the array list.&lt;br /&gt;
&lt;br /&gt;
The loop is repeated 10times to give me an average.&lt;br /&gt;
&lt;br /&gt;
I made the following change to the code&lt;br /&gt;
 arraylist_push( &amp;amp;alist, &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;i&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
this should add a different number one million times into the array list.&lt;br /&gt;
&lt;br /&gt;
My results showed that, apart from random errors, there is no difference in timing between adding the &lt;br /&gt;
&lt;br /&gt;
same number and adding different numbers to the array list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Q2 ==&lt;br /&gt;
First of all I changed the array growth factor from 2.0 to a number lower than 1; eg 0.9&lt;br /&gt;
&lt;br /&gt;
The result was an instant crash of the program. As expected ^___^&lt;br /&gt;
&lt;br /&gt;
Changing the growth factor to 3.0 saw an increase in performance by about 3-4 milliseconds, this must&lt;br /&gt;
&lt;br /&gt;
be because the function to expand the array had to be called less. I expected this performance boost to&lt;br /&gt;
&lt;br /&gt;
increase as the growth factor increased until the calculation was almost instant, when the array only needed&lt;br /&gt;
&lt;br /&gt;
to be expanded &amp;#039;&amp;#039;&amp;#039;once&amp;#039;&amp;#039;&amp;#039; due to the large growth factor. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Q3 ==&lt;br /&gt;
I added&lt;br /&gt;
&lt;br /&gt;
 printf(&amp;quot;time taken : %d for j = %d \n size is %d \n&amp;quot;, &amp;#039;&amp;#039;&amp;#039;j, clock() - t0, alist.capacity&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
Hopefully this will help me spot the time changes.&lt;br /&gt;
&lt;br /&gt;
Setting ARRAYLIST_MIN_ALLOC to 10000000 (a lot of memory so the array never runs out of space).&lt;br /&gt;
&lt;br /&gt;
The performance was slower by about ~30milliseconds for a loop putting a number into the array one&lt;br /&gt;
&lt;br /&gt;
million times. This was unexpected. I thought it would be slightly faster, as the array would never run&lt;br /&gt;
&lt;br /&gt;
out of space and the growth calculations won&amp;#039;t be needed each time.&lt;br /&gt;
&lt;br /&gt;
Maybe it took time to allocate such a large amount of memory to something.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Q4 ==&lt;br /&gt;
Added the line&lt;br /&gt;
 ensure_capacity( &amp;amp;alist, 10000000 );&lt;br /&gt;
&lt;br /&gt;
at the start of the code.&lt;br /&gt;
&lt;br /&gt;
The time now was the same as the previous sections, ie. before ARRAYLIST_MIN_ALLOC was set to 10000000&lt;br /&gt;
&lt;br /&gt;
faster by ~30milliseconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ran out of time :( spent too long reading the code trying to understand&lt;br /&gt;
&lt;br /&gt;
will finish later&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>