Skip to content

Instantly share code, notes, and snippets.

@z4none
Created June 11, 2019 14:41
Show Gist options
  • Save z4none/151787e158301e70b7bef0c0607b1ce0 to your computer and use it in GitHub Desktop.
Save z4none/151787e158301e70b7bef0c0607b1ce0 to your computer and use it in GitHub Desktop.
Get the current time in microseconds in C.
#include <sys/time.h>
/**
* Returns the current time in microseconds.
*/
long getMicrotime(){
struct timeval currentTime;
gettimeofday(&currentTime, NULL);
return currentTime.tv_sec * (int)1e6 + currentTime.tv_usec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment