#pragma once

#ifdef _WIN32
#include <windows.h>
#else
#include <time.h>
#endif

typedef struct {
#ifdef _WIN32
    LARGE_INTEGER start, freq;
#else
    struct timespec start;
#endif
} simple_timer;

static inline void timer_start(simple_timer *t) {
#ifdef _WIN32
    QueryPerformanceFrequency(&t->freq);
    QueryPerformanceCounter(&t->start);
#else
    clock_gettime(CLOCK_MONOTONIC, &t->start);
#endif
}

static inline double timer_elapsed(simple_timer *t) {
#ifdef _WIN32
    LARGE_INTEGER end;
    QueryPerformanceCounter(&end);
    return (double)(end.QuadPart - t->start.QuadPart) / t->freq.QuadPart;
#else
    struct timespec end;
    clock_gettime(CLOCK_MONOTONIC, &end);
    return (end.tv_sec - t->start.tv_sec) + (end.tv_nsec - t->start.tv_nsec) * 1e-9;
#endif
}
