Skip to content

Instantly share code, notes, and snippets.

@w1k1n9cc
Created June 7, 2016 15:48
Show Gist options
  • Select an option

  • Save w1k1n9cc/012be60361e73de86bee0bce51652aa7 to your computer and use it in GitHub Desktop.

Select an option

Save w1k1n9cc/012be60361e73de86bee0bce51652aa7 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;
}
@Buggem

Buggem commented Feb 20, 2025

Copy link
Copy Markdown

the guy above me is an average command and control person

@abdulkhafizov07

abdulkhafizov07 commented Dec 26, 2025

Copy link
Copy Markdown

Hello,
Is this the fastest way to get time in microseconds?

@f1redude123

Copy link
Copy Markdown

Thank you very much, this is very helpful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment