<?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%3Asdal039</id>
	<title>SE250:lab-1:sdal039 - 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%3Asdal039"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:sdal039&amp;action=history"/>
	<updated>2026-04-28T23:23: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-1:sdal039&amp;diff=4505&amp;oldid=prev</id>
		<title>Mark: 6 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:sdal039&amp;diff=4505&amp;oldid=prev"/>
		<updated>2008-11-03T05:18:45Z</updated>

		<summary type="html">&lt;p&gt;6 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; int main() {&lt;br /&gt;
  clock_t timeBefore, timeAfter, timeDiff, timeSum, timeAverage;&lt;br /&gt;
  long counter, repeatCounter;&lt;br /&gt;
 &lt;br /&gt;
  int sum;&lt;br /&gt;
  &lt;br /&gt;
  /* set initial timeSum value to 0 */&lt;br /&gt;
  timeSum = 0;	&lt;br /&gt;
 &lt;br /&gt;
  /*loop to repeat the process 100 times so an average value of */&lt;br /&gt;
  /* time can be calculated */&lt;br /&gt;
  for (repeatCounter = 0;repeatCounter &amp;lt; 100;repeatCounter++) {&lt;br /&gt;
    sum = 0;&lt;br /&gt;
    timeBefore = clock();&lt;br /&gt;
    &lt;br /&gt;
    for (counter=0;counter &amp;lt; 10000000;counter++) {&lt;br /&gt;
      sum++;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    timeAfter = clock();&lt;br /&gt;
    timeDiff = (timeAfter - timeBefore);&lt;br /&gt;
    &lt;br /&gt;
    timeSum = timeSum + timeDiff;&lt;br /&gt;
 &lt;br /&gt;
    printf(&amp;quot;Counter has been run: %d times.&amp;quot;, repeatCounter);&lt;br /&gt;
  }&lt;br /&gt;
 	 &lt;br /&gt;
  /*create average time*/&lt;br /&gt;
  timeAverage = timeSum / 100;	&lt;br /&gt;
 &lt;br /&gt;
  printf(&amp;quot;Sum: %d obtained after %ld something-seconds&amp;quot;, sum, timeAverage);	&lt;br /&gt;
  &lt;br /&gt;
  return 0;	 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Not knowing how to get an actual value of time from the clock() function, the data collected is more for comparison rather than an actual useful value.&lt;br /&gt;
&lt;br /&gt;
From the data collected below you can see what affect the variable type had on computing time.&lt;br /&gt;
Int: 22&lt;br /&gt;
Long: 21&lt;br /&gt;
Short: 21 *see below&lt;br /&gt;
Float: 82&lt;br /&gt;
Double: 82&lt;br /&gt;
&lt;br /&gt;
Int and long took the least amount of time, float and double took the longest amount of time.&lt;br /&gt;
&lt;br /&gt;
When first running the code I found that each time it ran, it gave a slightly different value for the time taken. While the difference wasn&amp;#039;t much, I decided to add in another loop which would run the process 100 times and average the result. This process took a little longer, but it gave a vastly more accurate result.&lt;br /&gt;
&lt;br /&gt;
As for &amp;#039;short&amp;#039;, I wasn&amp;#039;t quite sure how to get a value for this. &lt;br /&gt;
Being that it can&amp;#039;t hold very large values, and that any value for the loop counter less than about 1,000,000 returned a time difference that was too small to accurately measure, running the program gave a sum of ~16,000 which I guess would be the minimum/maximum value that short can hold before it overflows. &lt;br /&gt;
&lt;br /&gt;
In the code the loop increments the variable sum as well as the variable counter. When the line &amp;#039;sum++&amp;#039; was removed, there was a slight difference in computing time for incrementing 2 variables versus incrementing 1 variable (21.4 versus 21.9).&lt;br /&gt;
&lt;br /&gt;
All in all, for only starting learning C on Friday I feel that I have become a lot more comfortable with the language and hope that in future labs I will be able to focus more on the logic of what the question is asking, rather than how to actually code it.&lt;br /&gt;
&lt;br /&gt;
[[User:Sdal039|Sdal039]] 11:48, 4 March 2008 (NZDT)&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>