SE250:lab-1:zyan057
Jump to navigation
Jump to search
At first I tried to use clock() function in c to time one single addition in C. But the computer is too fast and all you can get is 0.00000 second. Therefore I wrote a loop to do 1000000000 additions and use the clock() function to find out the total time.
Here is the code I have used...
void main()
{
long time,a=0; time = clock(); for (int b=0;b<1000000000;b++) { a++; } time = (clock() - time); printf("%ld \n", time);
}
The results for int, long and short were similar, which were about 2300. The double and float type took longer to calculate, the results were above 8000.