Skip to content

Instantly share code, notes, and snippets.

@1901
Created January 5, 2013 14:55
Show Gist options
  • Save 1901/4461912 to your computer and use it in GitHub Desktop.
Save 1901/4461912 to your computer and use it in GitHub Desktop.
类似于Windows下的GetTickCount函数(但得到的时间不是开机后的时间)。
#include <iostream>
#include <sys/time.h>
//#include <time.h>
long getTickCount()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}
using namespace std;
int main(int argc, char *argv[])
{
int i = 0;
do
{
printf("getTickCount: %ld\n", getTickCount());
usleep(1000); // sleep 1 milliseconds
i++;
} while (i < 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment