SE250:lab-1:mabd065

From Marks Wiki
Jump to navigation Jump to search

At the beginning, i searched google for time functions and tried to use the time() function before and

after the for loop with no success.

After asking for help, i was told to use the clock() function instead of time.

After doing so, i got the following results:

For 100,000,000 time of increasing j by one (starting at J = 0):

Every time i run the test, a slitlty diffrent result is producted. I think this is due to how busy the processor and/or ram are on the time of running the test.

On PC (Windows vista), the results are as follows:

   Rounds   First        Second       Third
   int:     286 ticks || 288 ticks || 289 ticks
   long:    305 ticks || 288 ticks || 302 ticks
   short:   340 ticks || 297 ticks || 288 ticks
   double:  342 ticks || 321 ticks || 289 ticks
   float:   315 ticks || 289 ticks || 288 ticks


The code:

#include <stdio.h>
#include <time.h>

int main ()
{
	double start,end;
	double dif;

	double i;

	// Change the type for the J variable to get the variations i got
	float j=0;

	start = clock();

	for (i = 0; i < 100000000; i++)
	{
		j++;
	}

	end = clock();
	dif = end - start;

	printf("It took %.f ticks / %d s.\n", dif , CLOCKS_PER_SEC );

	return 0;
}

--Mabd065 11:47, 4 March 2008 (NZDT)