diff --git a/tools/fpack.c b/tools/fpack.c index 30e4ff5..ea711f8 100644 --- a/tools/fpack.c +++ b/tools/fpack.c @@ -12,15 +12,33 @@ #include #ifdef _WIN32 +#include #define PROGRAM_NAME "fpack.exe" #define fpack_fseek64(f, off, whence) _fseeki64((f), (off), (whence)) #define fpack_ftell64(f) _ftelli64((f)) #else +#include #define PROGRAM_NAME "fpack" #define fpack_fseek64(f, off, whence) fseeko((f), (off_t)(off), (whence)) #define fpack_ftell64(f) ftello((f)) #endif +static double now_seconds(void) +{ +#ifdef _WIN32 + LARGE_INTEGER freq, count; + + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&count); + return (double)count.QuadPart / (double)freq.QuadPart; +#else + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9; +#endif +} + #define FPACK_QUIET (1u << 0) #define FPACK_VERBOSE (1u << 1) #define FPACK_PROGRESS (1u << 2) @@ -258,6 +276,7 @@ int main(int argc, char **argv) size_t base_len; struct fpk_writer *w; int c; + double start_time; while ((c = getopt_long(argc, argv, "o:pqvh", long_opts, NULL)) != -1) { switch (c) { @@ -287,6 +306,8 @@ int main(int argc, char **argv) input_dir = argv[optind]; output = output_arg ? dup_str(output_arg) : derive_output_name(input_dir); + start_time = now_seconds(); + base_len = strlen(input_dir); while (base_len > 0 && IS_PATH_SEP(input_dir[base_len - 1])) base_len--; @@ -324,7 +345,8 @@ int main(int argc, char **argv) printf("\n"); if (!(flags & FPACK_QUIET)) - printf("wrote: %s (%lu entries)\n", output, (unsigned long)entry_count); + printf("wrote: %s (%lu entries) in %.3fs\n", output, + (unsigned long)entry_count, now_seconds() - start_time); free(output); return 0; diff --git a/tools/funpack.c b/tools/funpack.c index f17fc1b..74ccd9a 100644 --- a/tools/funpack.c +++ b/tools/funpack.c @@ -1,3 +1,7 @@ +#if !defined(_WIN32) +#define _POSIX_C_SOURCE 200809L +#endif + #include "fpk.h" #include #include @@ -8,17 +12,31 @@ #ifdef _WIN32 #include +#include #define MKDIR(path) _mkdir(path) -#else -#define MKDIR(path) mkdir(path, 0755) -#endif - -#ifdef _WIN32 #define PROGRAM_NAME "funpack.exe" #else +#include +#define MKDIR(path) mkdir(path, 0755) #define PROGRAM_NAME "funpack" #endif +static double now_seconds(void) +{ +#ifdef _WIN32 + LARGE_INTEGER freq, count; + + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&count); + return (double)count.QuadPart / (double)freq.QuadPart; +#else + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9; +#endif +} + #define FUNPACK_LIST (1u << 0) #define FUNPACK_PROGRESS (1u << 1) #define FUNPACK_QUIET (1u << 2) @@ -192,6 +210,7 @@ int main(int argc, char **argv) uint64_t count; uint64_t i; int c; + double start_time; while ((c = getopt_long(argc, argv, "d:lpqvh", long_opts, NULL)) != -1) { switch (c) { @@ -223,6 +242,8 @@ int main(int argc, char **argv) input = argv[optind]; + start_time = now_seconds(); + pak = fpk_open(input); if (!pak) { fprintf(stderr, "funpack: cannot open: %s\n", input); @@ -289,8 +310,8 @@ int main(int argc, char **argv) printf("\n"); if (!(flags & FUNPACK_QUIET)) - printf("unpacked: %s -> %s (%lu entries)\n", input, out_dir, - (unsigned long)count); + printf("unpacked: %s -> %s (%lu entries) in %.3fs\n", input, out_dir, + (unsigned long)count, now_seconds() - start_time); free(out_dir); return 0;