I want to use clock() to calculate the approximation of the cumulative amount of time used by the program since it started and here is part of my lines in main():
start = clock();
PRINTF("%d \n", start);
EightQueen(0,q); // it is a subfunction, I want to calculate the duration of it.
PRINTF("A total of %d solutions!\r\n", count);
end = clock();
PRINTF("%d \n", end);
PRINTF("%d s\n", (end-start)/CLOCKS_PER_SEC);
When I run the same program in my LPC812, it prints the result in the MCUXpresso's console, it print the right result of the time.
But when print in the PuTTY, ‘serial’ terminal. It prints a totally wrong result.The start time and the end time are exactly the same and whatever the real duration of the program should be, the start always equals to the end and exactly equals to 32.
I want to know how to fix it, thank you.
Solved! Go to Solution.
clock() is a semihosted function - it is implemented on the host. So, it will only ever work when you are running and connected to a debugger (otherwise it will return zero). If you want to calculate time, accurately, on your device, you will need to use one of the timers provided on your device.
clock() is a semihosted function - it is implemented on the host. So, it will only ever work when you are running and connected to a debugger (otherwise it will return zero). If you want to calculate time, accurately, on your device, you will need to use one of the timers provided on your device.
I got it. Thank you.