This commit is contained in:
2026-09-24 15:30:45 -03:00
commit a5af824c91
306 changed files with 58603 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#include <Log.h>
#include <io/Time.h>
#include <time.h>
#include <CMath.h>
#include <float.h>
static double freq = 0;
void time_init(void)
{
#ifdef _WIN32
LARGE_INTEGER li;
if (!QueryPerformanceFrequency(&li))
{
Err("Failed to query perfomance frequency!");
return;
}
freq = (double)(li.QuadPart) / 1000.0;
#endif
}
void time_start(TimeStamp* timer)
{
#ifdef _WIN32
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
*timer = (li.QuadPart / freq);
#else
struct timespec _t;
clock_gettime(CLOCK_MONOTONIC, &_t);
*timer = _t.tv_sec * 1000 + _t.tv_nsec / 1e6;
#endif
}
double time_end(TimeStamp* timer)
{
#ifdef _WIN32
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return (double)((li.QuadPart) / freq) - (*timer);
#else
struct timespec _t;
clock_gettime(CLOCK_MONOTONIC, &_t);
double current = _t.tv_sec * 1000 + _t.tv_nsec / 1e6;
return current - (*timer);
#endif
}