Skip to content

Instantly share code, notes, and snippets.

@almorel
Created April 11, 2013 15:18
Show Gist options
  • Save almorel/5364231 to your computer and use it in GitHub Desktop.
Save almorel/5364231 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#include <time.h>
int64_t timespecDiff(struct timespec *timeA_p, struct timespec *timeB_p)
{
return ((timeA_p->tv_sec * 1000000000) + timeA_p->tv_nsec) -
((timeB_p->tv_sec * 1000000000) + timeB_p->tv_nsec);
}
int main(int argc, char **argv)
{
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
// Some code I am interested in measuring
clock_gettime(CLOCK_MONOTONIC, &end);
uint64_t timeElapsed = timespecDiff(&end, &start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment