since I've never wrote programms for realtime systems on linux, I wonder, how I get a precise time?
On Arduino for example I use millis(), which returns the milli seconds since start of the programm.
Is <time.h> with clock() and CLOCKS_PER_SECOND the correct way?
Code: Select all
#include <time.h>
...
int millis(){
static clock_t start;
static bool firstRun=true;
if(firstRun){
firstRun = false;
start = clock();
}
clock_t now = clock();
clock_t diff = now-start;
double t = (double)diff/CLOCKS_PER_SEC;
return t*1000;
}