From 3b9d11951810c199297b01cba64c28b718fabd84 Mon Sep 17 00:00:00 2001 From: Mahesh Madhav <67384846+heshpdx@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:16:52 -0700 Subject: [PATCH] Reduce clock syscalls (#4303) Gate the sample of the clock by the tessedit_timing_debug flag, which is the only time it gets used anyway. This eliminates unnecessary clock_gettime() system calls. --- src/ccmain/control.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ccmain/control.cpp b/src/ccmain/control.cpp index 30afc47763..df661e7ece 100644 --- a/src/ccmain/control.cpp +++ b/src/ccmain/control.cpp @@ -1312,7 +1312,10 @@ void Tesseract::classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordD PointerVector best_words; // Points to the best result. May be word or in lang_words. const WERD_RES *word = word_data->word; - clock_t start_t = clock(); + clock_t start_t = 0; + if (tessedit_timing_debug) { + start_t = clock(); + } const bool debug = classify_debug_level > 0 || multilang_debug_level > 0; if (debug) { tprintf("%s word with lang %s at:", word->done ? "Already done" : "Processing", @@ -1364,8 +1367,8 @@ void Tesseract::classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordD } else { tprintf("no best words!!\n"); } - clock_t ocr_t = clock(); if (tessedit_timing_debug) { + clock_t ocr_t = clock(); tprintf("%s (ocr took %.2f sec)\n", word_data->word->best_choice->unichar_string().c_str(), static_cast(ocr_t - start_t) / CLOCKS_PER_SEC); }