<?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%3Ahpan027</id>
	<title>SE250:lab-3:hpan027 - 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%3Ahpan027"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:hpan027&amp;action=history"/>
	<updated>2026-06-04T17:34:55Z</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:hpan027&amp;diff=5546&amp;oldid=prev</id>
		<title>Mark: 15 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:hpan027&amp;diff=5546&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:20Z</updated>

		<summary type="html">&lt;p&gt;15 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Not a very exciting lab as most of the time is spent waiting for the programme to run.&lt;br /&gt;
&lt;br /&gt;
== Task 1 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following code was added to the arraylist.c file&lt;br /&gt;
&lt;br /&gt;
 int main () {&lt;br /&gt;
 &lt;br /&gt;
     ArrayList myArray;&lt;br /&gt;
     int i;&lt;br /&gt;
     int n = 1000000;&lt;br /&gt;
     element_t value = 3;&lt;br /&gt;
     clock_t clockStart;&lt;br /&gt;
     clock_t clockFinish;&lt;br /&gt;
     clock_t timeTaken;&lt;br /&gt;
 &lt;br /&gt;
     arraylist_init(&amp;amp;myArray);&lt;br /&gt;
 &lt;br /&gt;
     clockStart = clock();&lt;br /&gt;
 &lt;br /&gt;
     for (i = 0; i &amp;lt; n; i ++ ) {&lt;br /&gt;
 	arraylist_push(&amp;amp;myArray, value);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     clockFinish = clock();&lt;br /&gt;
 &lt;br /&gt;
     timeTaken = ( clockFinish - clockStart );&lt;br /&gt;
 &lt;br /&gt;
     printf(&amp;quot;%ld&amp;quot;, timeTaken);&lt;br /&gt;
     &lt;br /&gt;
     return 0; &lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The the time taken was recorded for different values of n between 1,000,000 to 1,000,000,000&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000&lt;br /&gt;
 clock = 46&lt;br /&gt;
&lt;br /&gt;
 n = 10,000,000&lt;br /&gt;
 clock = 672&lt;br /&gt;
&lt;br /&gt;
 n = 100,000,000&lt;br /&gt;
 clock = 6640&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
*Time taken scales in a somewhat linear fashion. However, sometime before n reaches the value of 1,000,000,000, the programme is stopped with the error message &amp;quot;assertion &amp;quot;alist-&amp;gt;arr != (element_t*)0&amp;quot;&amp;quot;. i.e. the programme has run out of memory and hence did not allocate any more to arr.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 2 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Growth factor: 1.5&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000&lt;br /&gt;
 clock = 94&lt;br /&gt;
&lt;br /&gt;
 n = 10,000,000&lt;br /&gt;
 clock = 671&lt;br /&gt;
&lt;br /&gt;
 n = 100,000,000&lt;br /&gt;
 clock = 7297&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
*No drastic change here. Takes a little bit longer, and runs out of memory at the same place&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Growth factor: 3.0&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000&lt;br /&gt;
 clock = 46&lt;br /&gt;
&lt;br /&gt;
 n = 10,000,000&lt;br /&gt;
 clock = 577&lt;br /&gt;
&lt;br /&gt;
 n = 100,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
*Slight improvement to speed here, but the program runs out of memory earlier&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Growth factor: 4.0&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000&lt;br /&gt;
 clock = 77&lt;br /&gt;
&lt;br /&gt;
 n = 10,000,000&lt;br /&gt;
 clock = 641&lt;br /&gt;
&lt;br /&gt;
 n = 100,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
 n = 1,000,000,000&lt;br /&gt;
 Programme runs out of memory&lt;br /&gt;
&lt;br /&gt;
*At this point it&amp;#039;s pretty clear that there aren&amp;#039;t enough data to draw any conclusions, so more data need to be collected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*The following data was collected using a loop with n as the counter variable.&lt;br /&gt;
 (n = 1000000; n &amp;lt; 100000000; n += 5000000)&lt;br /&gt;
&lt;br /&gt;
[[Image:hpan027lab3.jpg]]&lt;br /&gt;
&lt;br /&gt;
*Time in clock ticks along y axis, value of n along x. Each series represent a different growth factor&lt;br /&gt;
*We can see there is some relationship between time taken and growth factor - increasing growth factor tends to decrease time taken&lt;br /&gt;
*Higher growth factors run out of memory sooner&lt;br /&gt;
*The above relationship can be quite easily explained by how many times the array list has to be reallocated&lt;br /&gt;
&lt;br /&gt;
 	1.5x	2x	3x	4x	5x&lt;br /&gt;
 A	27	15	10	7	6&lt;br /&gt;
 B	11	6	4	3	2&lt;br /&gt;
&lt;br /&gt;
*Row A is the number of reallocations required for a given factor to reach n = 1,000,000&lt;br /&gt;
*Row B is the number of additional reallocations required for a given factor to reach n = 96,000,000&lt;br /&gt;
*For larger growth factors, less reallocations are required - especially ones dealing with large chunks of memory - hence less time is taken&lt;br /&gt;
&lt;br /&gt;
*The programme clearly runs out of memory somewhere between n = 10,000,000 and n = 100,000,000&lt;br /&gt;
*Closer examination of of values of n for different growth factors show that:&lt;br /&gt;
**Making the jump from 76,527,504 to 229,582,512 and 67,108,864 to 268,435,456 for factors 3x and 4x respectively results in the programme running out of memory&lt;br /&gt;
**Jumping from 31,250,000 to 156,250,000 for factor 5x did not cause any problems&lt;br /&gt;
**Hence the programme runs out of memory somewhere between 600mb to 875mb of memory used&lt;br /&gt;
*That was some pretty meaningless data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 3 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Looking at the value of ARRAYLIST_MIN_ALLOC vs the number of reallocations required to reach n = 1,000,000 showed that there shouldn&amp;#039;t really be much difference for differences in MIN_ALLOC, whereas increasing it by larger factors should have greater effects.&lt;br /&gt;
&lt;br /&gt;
 MIN_ALLOC	Number of realloc to reach n = 1,000,000&lt;br /&gt;
 8		17&lt;br /&gt;
 16		16&lt;br /&gt;
 32		15&lt;br /&gt;
 10000		7&lt;br /&gt;
 100000		3&lt;br /&gt;
&lt;br /&gt;
Results for n = 1,000,000 to n = 10,000,000 step 1,000,000&lt;br /&gt;
 		8	16	32	10000	100000&lt;br /&gt;
 1000000		62	46	62	62	61&lt;br /&gt;
 2000000		109	94	110	110	110&lt;br /&gt;
 3000000		157	157	156	187	156&lt;br /&gt;
 4000000		264	171	235	219	235&lt;br /&gt;
 5000000		329	250	297	250	282&lt;br /&gt;
 6000000		329	328	359	376	359&lt;br /&gt;
 7000000		406	438	439	437	453&lt;br /&gt;
 8000000		484	453	468	453	516&lt;br /&gt;
 9000000		579	562	593	515	546&lt;br /&gt;
&lt;br /&gt;
*For smaller steps of n there is no difference&lt;br /&gt;
&lt;br /&gt;
Hopefully there is some change for larger steps of n - as this is taking 1 minute each time it is run&lt;br /&gt;
&lt;br /&gt;
Results for n = 1,000,000 to n = 100,000,000 step 5,000,000&lt;br /&gt;
 	 	8	16	32	10000	100000&lt;br /&gt;
 1000000		62	62	62	78	62&lt;br /&gt;
 6000000		344	360	376	344	328&lt;br /&gt;
 11000000	688	641	671	734	609&lt;br /&gt;
 16000000	1015	1032	938	969	1016&lt;br /&gt;
 21000000	1360	1296	1328	1313	1328&lt;br /&gt;
 26000000	1422	1719	1563	1703	1703&lt;br /&gt;
 31000000	1984	1703	1781	1626	2016&lt;br /&gt;
 36000000	2312	2172	2406	2124	2062&lt;br /&gt;
 41000000	2657	2453	2468	2578	2297&lt;br /&gt;
 46000000	2906	2749	3047	3109	2515&lt;br /&gt;
 51000000	3000	3063	3031	3297	2734&lt;br /&gt;
 56000000	3468	3280	3203	3437	3360&lt;br /&gt;
 61000000	3548	3422	3609	3562	3969&lt;br /&gt;
 66000000	3969	3797	3969	4141	4266&lt;br /&gt;
 71000000	5016	4469	4625	4220	4703&lt;br /&gt;
 76000000	5375	5047	5891	4343	4797&lt;br /&gt;
 81000000	5422	5188	5563	4985	4937&lt;br /&gt;
 86000000	6047	5562	5687	5500	5469&lt;br /&gt;
 91000000	5640	5750	6046	5936	5343&lt;br /&gt;
 96000000	6079	6172	5813	5720	5703&lt;br /&gt;
&lt;br /&gt;
*Again no real difference&lt;br /&gt;
&lt;br /&gt;
The time taken was expected to drop but this didn&amp;#039;t really happen. This could be due to ratio of memory reallocations to the number of times that a variable is pushed&lt;br /&gt;
&lt;br /&gt;
i.e Memory is reallocated about 30 times, while there are about 970,000,000 calls to the arraylist_push function.&lt;br /&gt;
&lt;br /&gt;
However that doesn&amp;#039;t explain why changing the growth factor makes a difference while the the MIN_ALLOC value does not. &lt;br /&gt;
&lt;br /&gt;
It is therefore more likely that reallocating small chunks of memory does not take much time at all - which is really what changing the MIN_ALLOC variable reduces. Going from n = 1,000,000 to 100,000,000 still requires pretty much the same number of reallocs regardless of MIN_ALLOC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 4 ==&lt;br /&gt;
&lt;br /&gt;
Data with and without calls to the ensure_capacity function&lt;br /&gt;
 Without		With&lt;br /&gt;
 47		46&lt;br /&gt;
 360		265&lt;br /&gt;
 656		516&lt;br /&gt;
 953		844&lt;br /&gt;
 1281		1062&lt;br /&gt;
 1468		1250&lt;br /&gt;
 1922		1421&lt;br /&gt;
 2282		1672&lt;br /&gt;
 2656		2063&lt;br /&gt;
 2844		2421&lt;br /&gt;
 2985		2750&lt;br /&gt;
 3250		2906&lt;br /&gt;
 3563		3047&lt;br /&gt;
 3828		3311&lt;br /&gt;
 4391		3516&lt;br /&gt;
 5250		3749&lt;br /&gt;
 5250		4094&lt;br /&gt;
 5484		4266&lt;br /&gt;
 5531		4532&lt;br /&gt;
 6547		4797&lt;br /&gt;
&lt;br /&gt;
*There is a clear difference here. Notice that for smaller values of n, the difference is not as great. This reinforces the idea that larger chunks of memory takes more time to move - which is kind of intuitive in the first place.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 5 ==&lt;br /&gt;
&lt;br /&gt;
 	 		+1e6	+1e7	+1e8&lt;br /&gt;
 1000000			31	47	47&lt;br /&gt;
 6000000			468	297	281&lt;br /&gt;
 11000000		1001	626	546&lt;br /&gt;
 16000000		1656	937	843&lt;br /&gt;
 21000000		2657	1265	1048&lt;br /&gt;
 26000000		3843	1516	1265&lt;br /&gt;
 31000000		5266	2094	1422&lt;br /&gt;
 36000000		6781	2125	1687&lt;br /&gt;
 41000000		8452	2859	1953&lt;br /&gt;
 46000000		10750	3359	2141&lt;br /&gt;
 51000000		12937	3718	2391&lt;br /&gt;
 56000000		15173	4141	2891&lt;br /&gt;
 61000000		17954	4719	3063&lt;br /&gt;
 66000000		20469	5250	3328&lt;br /&gt;
 71000000		23188	5875	3172&lt;br /&gt;
 76000000		26938	6344	3813&lt;br /&gt;
 81000000		30343	7047	4047&lt;br /&gt;
 86000000		33548	7390	4250&lt;br /&gt;
 91000000		38188	8312	4578&lt;br /&gt;
 96000000		41781	8890	4767&lt;br /&gt;
 Calls to realloc	970	97	9.7&lt;br /&gt;
&lt;br /&gt;
[[Image:Hpan027Task5.jpg]]&lt;br /&gt;
&lt;br /&gt;
*The realloc calls make a more noticeable difference in larger numbers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 6 ==&lt;br /&gt;
&lt;br /&gt;
 arraylist_put(&amp;amp;myArray, value,0);&lt;br /&gt;
&lt;br /&gt;
*Needless to say it takes an unreasonable amount of time to have to shift the whole array every single time especially when dealing with such large values of n. I gave up waiting after ten minutes as I&amp;#039;ve finished typing up the rest of my report.&lt;br /&gt;
*For smaller values of n it is most likely putting a value at the front of the array will take much longer&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>