Obtenga la hora del sistema en milisegundos al principio, otra vez al final y reste.
para obtener el número de milisegundos desde 1970 en POSIX podría escribir:
struct timeval tv;
gettimeofday(&tv, NULL);
return ((((unsigned long long)tv.tv_sec) * 1000) +
(((unsigned long long)tv.tv_usec)/1000));
Para obtener el número de milisegundos desde 1601 en Windows que iba a escribir:
SYSTEMTIME systime;
FILETIME filetime;
GetSystemTime(&systime);
if (!SystemTimeToFileTime(&systime, &filetime))
return 0;
unsigned long long ns_since_1601;
ULARGE_INTEGER* ptr = (ULARGE_INTEGER*)&ns_since_1601;
// copy the result into the ULARGE_INTEGER; this is actually
// copying the result into the ns_since_1601 unsigned long long.
ptr->u.LowPart = filetime.dwLowDateTime;
ptr->u.HighPart = filetime.dwHighDateTime;
// Compute the number of milliseconds since 1601; we have to
// divide by 10,000, since the current value is the number of 100ns
// intervals since 1601, not ms.
return (ns_since_1601/10000);
Si te importaba a normalice la respuesta de Windows para que también devuelva la cantidad de milisegundos desde 1970, luego tendría que ajustar su respuesta en 11644473600000 milisegundos. Pero eso no es necesario si todo lo que te importa es el tiempo transcurrido.
Dupe, pero no se puede vincular en este momento –
La votación para cerrar fue demasiado poco, demasiado tarde. Tengo una respuesta funcional. Buen intento sin embargo. Por cierto, tampoco pude encontrar un enlace. –
¿Es para ventanas? entonces intente GetTickCount (API de Windows) –