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

		<summary type="html">&lt;p&gt;40 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Lab Report =&lt;br /&gt;
&lt;br /&gt;
This lab is to determine the time taken to execute an incrementing arraylist many times.&lt;br /&gt;
&lt;br /&gt;
Code used for the tests:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
&lt;br /&gt;
	int i;&lt;br /&gt;
	clock_t time_now;&lt;br /&gt;
	clock_t time_after;&lt;br /&gt;
	double time;&lt;br /&gt;
&lt;br /&gt;
	time_now = clock();&lt;br /&gt;
&lt;br /&gt;
	for(i = 0; i &amp;lt; 100,000,000; i++) {&lt;br /&gt;
		i = i+1;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	time_after = clock();&lt;br /&gt;
	time = (time_after - time_now) / (double)CLOCKS_PER_SEC;&lt;br /&gt;
&lt;br /&gt;
	printf(&amp;quot;Processing %d additions: %f seconds\n&amp;quot;, i, time);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Question 1 ==&lt;br /&gt;
&lt;br /&gt;
Question 1 is using default growth factor of *2&lt;br /&gt;
&lt;br /&gt;
(Growth Factor *2)&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.122 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.019 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 9.995 seconds&lt;br /&gt;
&lt;br /&gt;
== Question 2 ==&lt;br /&gt;
&lt;br /&gt;
=== Growth Factor *3 ===&lt;br /&gt;
&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.194 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.447 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.339 seconds&lt;br /&gt;
&lt;br /&gt;
=== Growth Factor *5 ===&lt;br /&gt;
&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.089 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.038 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 10.189 seconds&lt;br /&gt;
&lt;br /&gt;
=== Growth Factor *1.5 ===&lt;br /&gt;
&lt;br /&gt;
Time taken for 100,000,000 iterations: 10.698 seconds&lt;br /&gt;
Time taken for 100,000,000 iterations: 10.41 seconds&lt;br /&gt;
Time taken for 100,000,000 iterations: 10.475 seconds&lt;br /&gt;
&lt;br /&gt;
Up until now there is subtle difference between the growth factors. It&amp;#039;s safe to conclude that the memory is being allocated fast enough, but the putting of the values inside the array is what takes up the most time.&lt;br /&gt;
&lt;br /&gt;
=== Growth Factor *1.1 ===&lt;br /&gt;
&lt;br /&gt;
*Time taken for 100,000,000 iterations: 14.580 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 14.472 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 14.507 seconds&lt;br /&gt;
&lt;br /&gt;
Once you decrease the growth factor to 1.1, it now forms the bottleneck and the times increases significantly. The array isn&amp;#039;t expanding fast enough to add the values in, hence causing a delay.&lt;br /&gt;
&lt;br /&gt;
== Question 3 ==&lt;br /&gt;
&lt;br /&gt;
I increased ARRAYLIST_MIN_ALLOC to various values but not much changed until I changed it to:&lt;br /&gt;
&lt;br /&gt;
50000000&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Time taken for 100,000,000 iterations: 9.529 seconds&lt;br /&gt;
Time taken for 100,000,000 iterations: 9.436 seconds&lt;br /&gt;
Time taken for 100,000,000 iterations: 9.437 seconds&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can notice some difference at this stage, times are shorter, however, not much.&lt;br /&gt;
&lt;br /&gt;
== Question 4 ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*Time taken for 100,000,000 iterations: 9.145 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 9.052 seconds&lt;br /&gt;
*Time taken for 100,000,000 iterations: 9.033 seconds&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Times are definitely shorter as the array size is preallocated.&amp;lt;br /&amp;gt;&lt;br /&gt;
The times taken in this case is the time taken to insert the values into the array.&lt;br /&gt;
&lt;br /&gt;
== Question 5 ==&lt;br /&gt;
&lt;br /&gt;
I had to decrease the iterations to 1,000,000, since it would take way too long for the 100 million.&lt;br /&gt;
The growth factor is now + 1000 incremental.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* Time taken for 1000000 iterations: 2.707 seconds&lt;br /&gt;
* Time taken for 1000000 iterations: 2.742 seconds&lt;br /&gt;
* Time taken for 1000000 iterations: 2.751 seconds&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The times are longer significantly, as everytime the array runs out of space, it only allocates 1000. &amp;lt;br /&amp;gt;&lt;br /&gt;
Hence I had to decrease the iterations to 1,000,000  to reach a suitable time for testing.&lt;br /&gt;
&lt;br /&gt;
== Question 6 ==&lt;br /&gt;
&lt;br /&gt;
For this exercise, arraylist_put is used instead of push, and elements are added to the start of the array.&lt;br /&gt;
I also changed the iterations to 100,000 since it was taking very long.&lt;br /&gt;
&lt;br /&gt;
Code changed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (i = 0; i &amp;lt; 100000; i++) {&lt;br /&gt;
	arraylist_put(&amp;amp;a1, value, 0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* Time taken for 100000 iterations: 3.806 seconds&lt;br /&gt;
* Time taken for 100000 iterations: 3.837 seconds&lt;br /&gt;
* Time taken for 100000 iterations: 3.743 seconds&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The times are clearly much longer, in fact I had to keep decreasing the 0&amp;#039;s until 100,000. &amp;lt;br /&amp;gt;&lt;br /&gt;
I assume the reason for this is everytime you insert a value, you have to shift all the other values forward 1 space, hence increasing th  time taken significantly.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>