Created
January 5, 2013 14:55
-
-
Save 1901/4461912 to your computer and use it in GitHub Desktop.
类似于Windows下的GetTickCount函数(但得到的时间不是开机后的时间)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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