Microsecond time in C
Here is a handy function micro_time()
for getting time in microseconds in C:
#include <sys/time.h>
uint64_t micro_time() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * (uint64_t)1000000 + tv.tv_usec;
}
long start = micro_time();
/*
do some work
*/
long end = micro_time();
// print duration in miliseconds with decimals to microsecond level
printf("call %.3f ms\n", (end - start) / 1000.0);