replace gettimeofday with clock_gettime for ns granularity