SE250:lab-1:asin185

From Marks Wiki
Jump to navigation Jump to search

Lab One

Intro

-The work for lab one was quite easy but i needed some help to get started as i havnt done this for a while. After a while, just looking at the screen i got into it.We looked at the time taken to execute sereval addition loops by using thr "clock()" function. We took one hundred million as the standard value for testing the different data types.

-First we had to create a main class to carry all the methods.

#include <time.h>
#include <stdio.h>
void main (){}

-Then we Initialised the variable for the different data types and put them trough the loop to see how long it would take to - exectue.


int result = 0;
long t = clock();

for(int i = 0; i < 100000000 ; i++){
	result ++;
	}
	t = clock() - t;
	printf("%ld",t);

Then changing the result to all the different data types like ( int , long, short, float, double).

Results

Results are as follows for the amount of time taken to execute the loop 100,000,000 times. An average was taken from all the graphs after 10 trails for each data type.

Int = 307.7 Long = 309.4 Short = 314.6 Float = 444.9 Double = 442.6

File:Int.jpg File:Long.jpg File:Short.jpg File:Float.jpg File:Double.jpg

Conclusion

As you can see the the int takes the least amount of time as it is quite round and the others follow on after the the int.After the main layout was done then it was just a matter of changing the data type and recording it. Problems occured as the values varied to much and time of the data types didnt have any trend.I think i may need to practice more C programing after this lab.