From 6b492daddd682de986e3f983ecfc1d29ed70b0a0 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Tue, 5 Mar 2024 18:58:49 +0100 Subject: measure elapsed time for search --- src/main.cpp | 6 ++++-- src/main_windows.cpp | 13 +++++++++++++ src/platform.h | 1 + src/search.cpp | 2 ++ src/search.h | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index e21aead..e5b4fd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -355,8 +355,10 @@ void ts_create_gui(int window_w, int window_h) { ImGui::SameLine(); - ImGui::SetCursorPosX(window_w - 10.0f - ImGui::CalcTextSize("no search completed").x); - ImGui::Text("no search completed"); + if (current_search_result && current_search_result->search_completed) { + ImGui::SetCursorPosX(window_w - 10.0f - ImGui::CalcTextSize("999.999s elapsed").x); + ImGui::Text("%.3fs elapsed", current_search_result->timestamp/1000.0f); + } ImGui::EndChild(); ImGui::PopStyleVar(); } diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 61f9876..f657042 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -33,6 +33,7 @@ static HGLRC g_hRC; static WGL_WindowData g_MainWindow; static int g_Width; static int g_Height; +LARGE_INTEGER Frequency; bool CreateDeviceWGL(HWND hWnd, WGL_WindowData* data); void CleanupDeviceWGL(HWND hWnd, WGL_WindowData* data); @@ -50,6 +51,16 @@ static const char* _ts_platform_get_config_file_path(char* buffer) { return 0; } +uint64_t ts_platform_get_time(uint64_t compare) +{ + LARGE_INTEGER stamp; + QueryPerformanceCounter(&stamp); + if (compare != 0) { + return (stamp.QuadPart - compare) * 1000 / Frequency.QuadPart; + } + return stamp.QuadPart; +} + int main(int, char**) { // Create application window @@ -92,6 +103,8 @@ int main(int, char**) ImGui_ImplWin32_InitForOpenGL(hwnd); ImGui_ImplOpenGL3_Init(); + QueryPerformanceFrequency(&Frequency); + ts_init(); ts_load_images(); diff --git a/src/platform.h b/src/platform.h index edaee4c..1fb032d 100644 --- a/src/platform.h +++ b/src/platform.h @@ -32,5 +32,6 @@ typedef enum t_ts_file_open_error ts_file_content ts_platform_read_file(char *path, const char *mode); void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir = nullptr); void ts_platform_list_files(ts_search_result* result); +uint64_t ts_platform_get_time(uint64_t compare = 0); // if compare is not 0, return difference between timestamp and now, in milliseconds. #endif \ No newline at end of file diff --git a/src/search.cpp b/src/search.cpp index 1e7241c..93cb9e9 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -98,6 +98,7 @@ ts_search_result *ts_create_empty_search_result() new_result_buffer->max_file_size = megabytes(1000); new_result_buffer->memory = ts_memory_bucket_init(megabytes(1)); new_result_buffer->prev_result = current_search_result; + new_result_buffer->timestamp = ts_platform_get_time(); new_result_buffer->files = ts_array_create(sizeof(ts_found_file)); new_result_buffer->files.reserve_jump = FILE_RESERVE_COUNT; @@ -365,6 +366,7 @@ static void *_ts_list_files_thread(void *args) while (!info->search_completed) { if (info->completed_match_threads == info->max_ts_thread_count) { info->search_completed = true; // No memory is written after this point. + info->timestamp = ts_platform_get_time(info->timestamp); } ts_thread_sleep(10); } diff --git a/src/search.h b/src/search.h index 5b5f4b7..3bae1a3 100644 --- a/src/search.h +++ b/src/search.h @@ -27,6 +27,7 @@ typedef struct t_ts_search_result int file_count; ts_memory_bucket memory; struct t_ts_search_result* prev_result; + uint64_t timestamp; // thread syncing ts_mutex mutex; -- cgit v1.2.3-70-g09d2