没有完全等同于PHP的microtime(),但您可以使用基于以下代码的类似功能的函数:
#include <sys/time.h>
struct timeval time;
gettimeofday(&time, NULL); #This actually returns a struct that has microsecond precision.
long microsec = ((unsigned long long)time.tv_sec * 1000000) + time.tv_usec;
Run Code Online (Sandbox Code Playgroud)
(基于:http://brian.pontarelli.com/2009/01/05/getting-the-current-system-time-in-milliseconds-with-c/)
unsigned __int64 freq;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
double timerFrequency = (1.0/freq);
unsigned __int64 startTime;
QueryPerformanceCounter((LARGE_INTEGER *)&startTime);
//do something...
unsigned __int64 endTime;
QueryPerformanceCounter((LARGE_INTEGER *)&endTime);
double timeDifferenceInMilliseconds = ((endTime-startTime) * timerFrequency);
Run Code Online (Sandbox Code Playgroud)
(由Darcara回答,来自:https://stackoverflow.com/a/4568649/330067 )