#include "myLog.h"
#include <cstdio>
#include <cstring>
#include <sys/time.h>
#include <unistd.h>

static long now_us() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec * 1000000L + tv.tv_usec;
}

int main() {
    printf("=== Log Latency Test ===\n\n");

    long t0 = now_us();
    log_init(NULL);
    long t1 = now_us();
    printf("log_init took %ld us\n", t1 - t0);

    for (int i = 0; i < 100; i++) {
        LOG_I("latency test msg #%d", i);
    }
    long t2 = now_us();
    printf("100 LOG_I calls queued in %ld us\n", t2 - t1);

    printf("waiting 1s for async output...\n");
    usleep(1000000);

    long t3 = now_us();
    printf("total elapsed %ld us, log_flush...\n", t3 - t0);
    log_flush();
    usleep(200000);

    printf("=== done ===\n");
    log_cleanup();
    return 0;
}
