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

		<summary type="html">&lt;p&gt;13 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introduction==&lt;br /&gt;
&amp;lt;p&amp;gt;First I had to remember how to write a program in C since I haven’t done so in months, after a bit of fiddling around I started to remember some of the things you need to do in C.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Then I wrote a for loop to calculate adding 1 to i for x amount of times.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The lab exercise sheet mentioned the clock() function. I have no idea how this function works initially so I had to go on google to search up the input/output characteristics of this function.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;After some searching I put up some code to calculate the time before the for loop starts then immediately after it. I then calculated the difference between those times to get how long it look to calculate the additions in the for loop.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I realised the time difference wasn’t given in seconds, it was given in ticks.  I found that if I divided the ticks by clocks_per_sec it will give the seconds.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code==&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; 2000000000; 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: %.10lf 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;
==Results==&lt;br /&gt;
&amp;lt;strong&amp;gt;I then tested for the following values:&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 10,000,000; 0.03 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 50,000,000; 0.18 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 100,000,000; 0.34 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 200,000,000; 0.63 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 1,000,000,000; 3.3 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;I = 2,000,000,000; 6.32 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Since I had spare time, I compiled and ran the code on the CS linux server. The results were very different&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Processing 100,000,000 additions: 1.4800000000 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Processing 500,000,000 additions: 7.4000000000 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Processing 1,000,000,000 additions: 14.7300000000 seconds&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&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. It&amp;#039;s safe to say that the linux server is much slower.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>