Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++ stream for log messages and use it in two debug messages #4314

Merged
merged 4 commits into from
Sep 4, 2024

Conversation

stweil
Copy link
Contributor

@stweil stweil commented Sep 3, 2024

The two debug message print execution times, previously in units of 0.01 seconds, now in milliseconds.

In function ErrorCounter::ComputeErrorRate the new code normally also avoids a call of clock() which is only needed for the debug message.

The new C++ stream tesserr can be used as an alternative to tprintf which is type safe and avoids lots of type casts.

Optimize also the code a little bit.

Signed-off-by: Stefan Weil <[email protected]>
Optimize also the code, replace tprintf by C++ stream
and call clock() only when needed.

Signed-off-by: Stefan Weil <[email protected]>
@stweil
Copy link
Contributor Author

stweil commented Sep 3, 2024

The sw builds failed. This is hopefully now fixed by adding TESS_API for tesserr. I wonder why autoconf and cmake builds work fine without it.

@stweil stweil merged commit 4f43536 into tesseract-ocr:main Sep 4, 2024
6 of 7 checks passed
@stweil stweil deleted the optimize branch September 4, 2024 03:22
tprintf("%s (ocr took %.2f sec)\n", word_data->word->best_choice->unichar_string().c_str(),
static_cast<double>(ocr_t - start_t) / CLOCKS_PER_SEC);
if (timing_debug) {
total_time = clock() - total_time;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why now to use c++11 chrono::steady_clock::now() (https://en.cppreference.com/w/cpp/chrono/steady_clock - most suitable for measuring intervals) instead of std::clock()?
AFAIK it should be more platform consistent than `std::clock()'....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use it any time, but in time critical code we'd have to check that it does not cost more resources than clock().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants