I am trying to read data from the ADC in the Beagle Bone, running Angstrom Linux distribution. I need to use a delay mechanism like sleep()
, to only read samples at specific time, to help conform to a specific sample rate.
I also am required to calculate the execution time.
Here is a sample POC (proof of concept), to demonstrate the problem I am facing:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
clock_t begin, end;
while(1)
{
begin = clock();
sleep(1); // delay for 1 sec
end = clock();
printf("Execution time = %f\n",((float)(end-begin)/CLOCKS_PER_SEC));
}
}
I always get the execution time as 0.000000
.
Why do I not get my result as 1.000000
seconds? My guess is calling sleep()
will pre-empt my program, but I am not sure.
What other option do I have to calculate elapsed execution time which includes a delay?