SE250:lab-1:srag014

From Marks Wiki
Jump to navigation Jump to search

Started off by researching on the internet about the clock function as I have never come across it before. Also had to do some research on C as I haven't used it that much (just used a book to execute simple programs ie hello world). So this made this lab quite challenging. Since I had a bit of java experience, I was able to write the loop for the additions.

for (x=0; x < 10000000; x++){

       x=x+1;

}

I found the clock function really confusing and the program i wrote had a lot of syntax errors in it. I also found out that the clock function returns the time in ticks and not seconds and the solution to get the time in seconds would be divide the time difference in ticks by CLOCKS_PER_SEC.

time=(end_time - start_time)/(double) CLOCKS_PER_SEC;

With some help from my neighbors and tutors I managed to fix all my errors and got the code to compile and run.

I got some results that i was not expecting at all. I ran the program a few times but I got different results all the time which was pretty surprising to me as I was using the same machine and expected the same result all the time.

Here are my results for x=10,000,000 Try #1:0.336 seconds Try #2:0.342 seconds Try #3:0.351 seconds Try #4:0.354 seconds Try #5:0.330 seconds

The general trend i could derive from my results were that the time seemed to increase everytime i ran the program.Another strange thing I noticed was when I closed any extra windows the time seemed to decrease which tells me that the time taken to execute an addition loop in C really depends on the system being used and what type of operations are running at the time of the program execution.