添加获取时间戳函数用于测试性能

This commit is contained in:
2025-08-19 00:48:10 +08:00
parent 36941aef25
commit bb61bfcd2e
3 changed files with 11 additions and 0 deletions

View File

@@ -3,12 +3,14 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/time.h>
#define LENGTH(X) (sizeof(X) / sizeof(X)[0])
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
double get_time();
void die(const char *format, ...);
void *ecalloc(size_t number_of_member, size_t member_size);

View File

@@ -197,8 +197,11 @@ void set_wallpaper_by_index(uint32_t index) {
wallpaper_config, monitors, index, screen_size->width, screen_size->height);
if (wallpaper) {
double start = get_time();
set_wallpaper(wallpaper);
double end = get_time();
free(wallpaper);
printf("set wallpaper cost: %fs\n", end - start);
}
free(screen_size);

View File

@@ -7,6 +7,12 @@
#include <string.h>
#include <unistd.h>
double get_time() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
void die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);