( apal | 2022. 11. 17., cs – 10:23 )

Tudsz csinalni a fentiek alapjan relative egyszeruen:

#include <stdio.h>
#include <sys/time.h>
#include <stdint.h>
#include <inttypes.h>

uint64_t getmicroseconds(void)
{
 struct timeval tv;
 uint64_t       r;
 gettimeofday(&tv,NULL);
 r=(uint64_t)tv.tv_sec*(uint64_t)1000000+(uint64_t)tv.tv_usec;
 return(r);
}

/* ... */

uint64_t t0,t1;
t0=getmicroseconds();
do_something_lengthy();
t1=getmicroseconds();
printf("Elapsed time: %" PRIu64 "\n",t1-t0);