<?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-1%3AMaintainers_report</id>
	<title>SE250:lab-1:Maintainers report - 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-1%3AMaintainers_report"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:Maintainers_report&amp;action=history"/>
	<updated>2026-04-24T13:01:06Z</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-1:Maintainers_report&amp;diff=4229&amp;oldid=prev</id>
		<title>Mark: 57 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:Maintainers_report&amp;diff=4229&amp;oldid=prev"/>
		<updated>2008-11-03T05:18:39Z</updated>

		<summary type="html">&lt;p&gt;57 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Different ways class did the lab==&lt;br /&gt;
&lt;br /&gt;
There were four basic methods people used to measure the addition time:&lt;br /&gt;
&lt;br /&gt;
#Using just one loop with an addition inside - either &amp;#039;&amp;#039;for&amp;#039;&amp;#039; or &amp;#039;&amp;#039;while&amp;#039;&amp;#039;&lt;br /&gt;
#Using two loops, one with an addition inside and another without one - either &amp;#039;&amp;#039;for&amp;#039;&amp;#039; or &amp;#039;&amp;#039;while&amp;#039;&amp;#039;&lt;br /&gt;
#Using two loops, one with a single addition inside and another with two additions inside - either &amp;#039;&amp;#039;for&amp;#039;&amp;#039; or &amp;#039;&amp;#039;while&amp;#039;&amp;#039;&lt;br /&gt;
#Using a nested loop. A &amp;#039;&amp;#039;for&amp;#039;&amp;#039; loop inside either a &amp;#039;&amp;#039;while&amp;#039;&amp;#039; or &amp;#039;&amp;#039;for&amp;#039;&amp;#039; loop.&lt;br /&gt;
#*The inside loop was timed and the outer was loop used to do many trials to take an average.&lt;br /&gt;
&lt;br /&gt;
For all methods we need to declare two &amp;#039;&amp;#039;clock_t&amp;#039;&amp;#039; type variables to calculate the time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clock_t start, finish;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everyone ran the timed loop from about 1 million to a billion times (This is shown as the &amp;#039;&amp;#039;LIMIT&amp;#039;&amp;#039; variable in the examples). This is because if a smaller number of additions were done, the time taken is very low and is very close to zero.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;In all examples, &amp;#039;&amp;#039;&amp;#039;i&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;j&amp;#039;&amp;#039;&amp;#039; are declared as &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;s. The variables &amp;#039;&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;b&amp;#039;&amp;#039;&amp;#039; are tested for &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;short&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;long&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;float&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;double&amp;#039;&amp;#039;&amp;#039;.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
===Single loop with addition inside===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start = clock();&lt;br /&gt;
for ( i = 0; i &amp;lt; LIMIT; i++ ) {&lt;br /&gt;
	a = a + 1;&lt;br /&gt;
}&lt;br /&gt;
finish = clock();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Two loops - empty and with addition===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start = clock();&lt;br /&gt;
for ( i = 0; i &amp;lt; LIMIT; i++ ) { }&lt;br /&gt;
end = clock();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The loop with addition is the same as the first example.&lt;br /&gt;
&lt;br /&gt;
===Two loops - one and two additions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start = clock();&lt;br /&gt;
for ( i = 0; i &amp;lt; LIMIT; i++ ) {&lt;br /&gt;
	a = a + 1;&lt;br /&gt;
	b = b + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The loop with a single addition is the same as the first example.&lt;br /&gt;
&lt;br /&gt;
===Nested loops - inside loop timed===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;A person used a nested for loop because of the limit of the type of variable. But this can be avoided by using a different variable for the loop counter from the one used for the addition.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In this example &amp;#039;&amp;#039;NUM_OF_TRIALS&amp;#039;&amp;#039; is the number of trials done of &amp;#039;&amp;#039;LIMIT&amp;#039;&amp;#039; additions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
double total_time = 0;&lt;br /&gt;
start = clock();&lt;br /&gt;
for ( i = 0; i &amp;lt; NUM_OF_TRIALS; i++ ) {&lt;br /&gt;
	start = clock();&lt;br /&gt;
	for ( j = 0; j &amp;lt; LIMIT; j++ ){&lt;br /&gt;
		a = a + 1;&lt;br /&gt;
	}&lt;br /&gt;
	end = clock();&lt;br /&gt;
	&lt;br /&gt;
	total_time = total_time + ( end - start );&lt;br /&gt;
}&lt;br /&gt;
finish = clock();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To convert total execution time of loops into seconds:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
double seconds = (double) (end - start) / (double) CLOCKS_PER_SEC;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results from the class==&lt;br /&gt;
&lt;br /&gt;
A lot of the reports didn’t state the results since many people did not generate proper results, either because they did not finish the lab or because the results are clearly wrong (negative time etc.).&amp;lt;br/&amp;gt;&lt;br /&gt;
As for people that did have the results:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The typical pattern seems to be:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Times shorter for the types int, short, long&lt;br /&gt;
*Times longer for the types double, floats&lt;br /&gt;
*CS Linux server is slower than the lab PCs&lt;br /&gt;
*Empty loop takes longer to process than a loop with an addition in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Here are some examples on what people have found / said:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;From: [[SE250:lab-1:dcho040]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Type   Int   long  Short Float Double&lt;br /&gt;
--------------------------------------&lt;br /&gt;
Test1  2346  2334  3011  9074  9397&lt;br /&gt;
Test2  2463  2339  3251  9295  9122&lt;br /&gt;
Test3  2447  2343  3086  9029  9054&lt;br /&gt;
Test4  2337  2373  2981  9056  9053&lt;br /&gt;
Test5  2346  2336  2991  9026  9057&lt;br /&gt;
--------------------------------------&lt;br /&gt;
AVG    2388  2345  3064  9096  9137&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;From: [[SE250:lab-1:twon069]] 1,000,000,000 additions&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int - 2.192sec&lt;br /&gt;
double - 8.262sec&lt;br /&gt;
float - 8.629sec&lt;br /&gt;
long - 2.404sec&lt;br /&gt;
short - 2.583sec&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;From: [[SE250:lab-1:gfun006]] 1,000,000,000 additions&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- Time elapsed to execute an int addition command is: 3.649000 seconds&lt;br /&gt;
- Time elapsed to execute an long addition command is: 3.122000 seconds&lt;br /&gt;
- Time elapsed to execute an short addition command is: 3.030900 seconds&lt;br /&gt;
- Time elapsed to execute an float addition command is: 4.826000 seconds&lt;br /&gt;
- Time elapsed to execute an double addition command is: 4.746000 seconds &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Using the linux server to run the code, from: [[SE250:lab-1:sshi080]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* Processing 100,000,000 additions: 1.4800000000 seconds&lt;br /&gt;
* Processing 500,000,000 additions: 7.4000000000 seconds&lt;br /&gt;
* Processing 1,000,000,000 additions: 14.7300000000 seconds&lt;br /&gt;
&lt;br /&gt;
The calculations took much longer, the 1 billion additions comparison were 6.32 on the local machine and 14.73 seconds on the linux server.&lt;br /&gt;
It&amp;#039;s safe to say that the linux server is much slower. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Empty loop taking longer than the addition loop!, from [[SE250:lab-1:jham005]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
double float long int short noop &lt;br /&gt;
484    469   391  390 360   375    &lt;br /&gt;
469    469   391  391 359   391    &lt;br /&gt;
453    453   390  453 359   390    &lt;br /&gt;
469    453   391  438 360   407    &lt;br /&gt;
469    469   391  422 343   390    &lt;br /&gt;
437    453   406  406 360   391    &lt;br /&gt;
469    453   390  437 359   391    &lt;br /&gt;
469    469   391  438 360   390    &lt;br /&gt;
453    453   391  406 343   375    &lt;br /&gt;
468    469   390  422 375   391    &lt;br /&gt;
(CLOCKS_PER_SEC is 1,000)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Recommended  method==&lt;br /&gt;
The best method that we found was using two loops, one empty and other with an addition inside it. We use this because it is very easy to implement and time.&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
// time.h is used for the clock() function, clock_t type and the CLOCKS_PER_SEC macro&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// LIMIT = how many additions to do = 1 billion&lt;br /&gt;
#define LIMIT 1000000000&lt;br /&gt;
&lt;br /&gt;
int main ( void )&lt;br /&gt;
{&lt;br /&gt;
	// Loop counter, always INT.&lt;br /&gt;
	int n = 0;&lt;br /&gt;
	// Addition variable. Simply changing the data type of this variable, we can test addition times for different data types.&lt;br /&gt;
	double i = 0;&lt;br /&gt;
	&lt;br /&gt;
	// Holds the number of clock ticks elapsed before the start of the loop&lt;br /&gt;
	clock_t t0;&lt;br /&gt;
	// Variables that hold the times for the empty loop and the one with addition, respectively.&lt;br /&gt;
 	double empty, full;&lt;br /&gt;
&lt;br /&gt;
	// Empty loop&lt;br /&gt;
 	t0 = clock();&lt;br /&gt;
 	for ( n = 0; n &amp;lt; LIMIT; n++ ) {&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
        // The time taken for the empty loop&lt;br /&gt;
 	empty = (double)(clock( ) - t0) / CLOCKS_PER_SEC;&lt;br /&gt;
	&lt;br /&gt;
	// Loop with addition&lt;br /&gt;
 	t0 = clock();&lt;br /&gt;
 	for ( n = 0; n &amp;lt; LIMIT; n++ ) {&lt;br /&gt;
		// The addition being timed. NOTE: If a variables&amp;#039; limit is reached, then it&amp;#039;s value is reset.&lt;br /&gt;
 		i = i + 1;&lt;br /&gt;
 	}&lt;br /&gt;
        // The time taken for the loop with addtions&lt;br /&gt;
 	full = (double)(clock() - t0) / CLOCKS_PER_SEC;&lt;br /&gt;
	&lt;br /&gt;
	printf( &amp;quot;1 billion times in EMPTY for loop take     %f s\n&amp;quot;, empty );&lt;br /&gt;
	printf( &amp;quot;1 billion addition operations in FULL take %f s\n&amp;quot;, full );&lt;br /&gt;
 	printf( &amp;quot;1 billion addition operations take         %f s\n&amp;quot;, full - empty ) ;&lt;br /&gt;
	&lt;br /&gt;
 	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
===Windows Vista Enterprise - Cygwin===&lt;br /&gt;
Level 1 Computer Science Lab (iMac)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
1 billion times in EMPTY for loop take     2.558000 s&lt;br /&gt;
1 billion addition operations in FULL take 2.340000 s&lt;br /&gt;
1 billion addition operations take         -0.21800 s&lt;br /&gt;
&lt;br /&gt;
long&lt;br /&gt;
1 billion times in EMPTY for loop take     2.652000 s&lt;br /&gt;
1 billion addition operations in FULL take 2.434000 s&lt;br /&gt;
1 billion addition operations take         -0.218000 s&lt;br /&gt;
&lt;br /&gt;
short&lt;br /&gt;
1 billion times in EMPTY for loop take     2.402000 s&lt;br /&gt;
1 billion addition operations in FULL take 3.619000 s&lt;br /&gt;
1 billion addition operations take         1.217000 s&lt;br /&gt;
&lt;br /&gt;
float&lt;br /&gt;
1 billion times in EMPTY for loop take     2.589000 s&lt;br /&gt;
1 billion addition operations in FULL take 3.183000 s&lt;br /&gt;
1 billion addition operations take         0.594000 s&lt;br /&gt;
&lt;br /&gt;
double&lt;br /&gt;
1 billion times in EMPTY for loop take     2.745000 s&lt;br /&gt;
1 billion addition operations in FULL take 3.291000 s&lt;br /&gt;
1 billion addition operations take         0.546000 s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mac OS X Leopard - gcc===&lt;br /&gt;
Level 1 Computer Science Lab (iMac)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
1 billion times in EMPTY for loop take     2.925953 s&lt;br /&gt;
1 billion addition operations in FULL take 2.923014 s&lt;br /&gt;
1 billion addition operations take         -0.002939 s&lt;br /&gt;
&lt;br /&gt;
long&lt;br /&gt;
1 billion times in EMPTY for loop take     2.928598 s&lt;br /&gt;
1 billion addition operations in FULL take 2.923283 s&lt;br /&gt;
1 billion addition operations take         -0.005315 s&lt;br /&gt;
&lt;br /&gt;
short&lt;br /&gt;
1 billion times in EMPTY for loop take     2.924871 s&lt;br /&gt;
1 billion addition operations in FULL take 2.920313 s&lt;br /&gt;
1 billion addition operations take         -0.004558 s&lt;br /&gt;
&lt;br /&gt;
float&lt;br /&gt;
1 billion times in EMPTY for loop take     2.924885 s&lt;br /&gt;
1 billion addition operations in FULL take 3.760510 s&lt;br /&gt;
1 billion addition operations take         0.835625 s&lt;br /&gt;
&lt;br /&gt;
double&lt;br /&gt;
1 billion times in EMPTY for loop take     2.925178 s&lt;br /&gt;
1 billion addition operations in FULL take 3.763027 s&lt;br /&gt;
1 billion addition operations take         0.837849 s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Conclusions &amp;amp; Discussion===&lt;br /&gt;
*Overall, Windows Vista seems to be faster with addition compared to Mac OS X (Note that they are both on the same machine)&lt;br /&gt;
**But when the time difference (full - empty) is calculated, Mac OS X gives smaller times for &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;short&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;long&amp;#039;&amp;#039;&amp;#039;. The values are about 1000 times smaller! But for the types &amp;#039;&amp;#039;&amp;#039;float&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;double&amp;#039;&amp;#039;&amp;#039;, Mac OS X gives higher values compared to Vista!&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;long&amp;#039;&amp;#039;&amp;#039; took the shortest amount of time.&lt;br /&gt;
**The weird thing was that on Vista the &amp;#039;&amp;#039;&amp;#039;short&amp;#039;&amp;#039;&amp;#039; type took six times as long as the &amp;#039;&amp;#039;&amp;#039;long&amp;#039;&amp;#039;&amp;#039; data type. One reason for this might be because the limit for the &amp;#039;&amp;#039;&amp;#039;short&amp;#039;&amp;#039;&amp;#039; type is exceeded multiple times. This might have an extra step involved that we don&amp;#039;t know about. But on the Mac this did not happen. &amp;#039;&amp;#039;&amp;#039;short&amp;#039;&amp;#039;&amp;#039; actually took less time than &amp;#039;&amp;#039;&amp;#039;long&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
These results are certainly not what we expected and it is very hard to think about why these things happen. But overall &amp;#039;&amp;#039;&amp;#039;int&amp;#039;&amp;#039;&amp;#039; seems to take the shortest amount of time and &amp;#039;&amp;#039;&amp;#039;float&amp;#039;&amp;#039;&amp;#039; took the longest.&lt;br /&gt;
&lt;br /&gt;
==Common Errors, Problems and Misunderstandings==&lt;br /&gt;
*The main sort of problem that almost everyone had was that their lack of practice of C, starting again after having that 4-5 months break was a challenge.&amp;lt;br /&amp;gt;&lt;br /&gt;
*Another major problem was syntax errors but this is expected due to the lack of C programming over the holidays.&amp;lt;br /&amp;gt;&lt;br /&gt;
*People tried using EMACS but encountered some problems mostly because they are unfamiliar with it and had to revert back to Visual Studio. Since this was covered in a recent lecture (6/3/08), this shouldn’t be a problem from now.&amp;lt;br /&amp;gt;&lt;br /&gt;
*Major error some people got was that they were getting negative values.&amp;lt;br /&amp;gt;&lt;br /&gt;
*The clock function returning with result as 0 was another error but this was due to the value being too small and when changed to a higher value this error was resolved.&amp;lt;br /&amp;gt;&lt;br /&gt;
*There was general confusion about the clock function, as in where to place the clock function (whether inside the addition loop or outside it) and what the clock function actually does (gives result in ticks and doesn’t give actual computer time).&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Improvements for 2009==&lt;br /&gt;
*The lab itself for 2009 should be left as it is because this lab is a good revision tool and a good way of getting back into the flow of things in regards to C programming. The lab acts a good start to the course too as it basically reviews some of the key basic properties required for everyday programming like loops, basic syntax etc. It also introduces a new idea of the clock function which is quite interesting and also quite challenging to implement.&amp;lt;br /&amp;gt;&lt;br /&gt;
*Things that could be changed before the lab could be giving students an introduction to EMACS as this will give them another option other than visual studio and also maybe a revision lecture on C, just generally going over everything like syntax and also an introduction to the clock function. This will save time and also eliminate a large number of errors and problems that maybe encountered.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>