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

Timer: Add a timer for code-benchmarking with RAII #555

Closed
wants to merge 3 commits into from

Conversation

insunaa
Copy link
Contributor

@insunaa insunaa commented Aug 31, 2024

🍰 Pullrequest

This PR adds a timer to benchmark code performance.

To use it simply create a new ChronoTimeTracker object and let it go out of scope, or delete it. Example:

{
    ChronoTimeTracker bench;
    // some code you want to benchmark
}

or

ChronoTimeTracker* bench = new ChronoTimeTracker();
// some code you want to benchmark
delete bench;

The time can also be polled at runtime with

ChronoTimeTracker bench;
while(1)
{
    sLog.outDebug("%ld", bench.elapsedSeconds().count());
}

Please note that measurements taken like this come with variance and should only be trusted in aggregate

@killerwife
Copy link
Contributor

This is why we have grafana integration. Adding two lines of code in places can be done on anyones local. Not sure this is needed at all. (as a matter of fact i used to do it regularly, without the need for raii)

@insunaa
Copy link
Contributor Author

insunaa commented Aug 31, 2024

yeah, the grafana-based metrics are really neat for long-term review of things, but they don't help much while actively working on some code. with this I can just plop in an object, compile run and see immediately in console if what I did was garbage or decent. With the regular metrics it is powerful when observing a running server over time

This isn't meant for runtime use, all instances of ChronoTimeTracker should be removed when changes are completed, this is just to simplify development, and so that I don't have to keep a patch of this class around to apply and delete every time I work on a new branch.
It may make sense to change this so that print adds the name of the timer in the output

@killerwife
Copy link
Contributor

I have warmed up to the idea, under the condition you put it in its own separate header file, not where you put it currently. And put the destructor implementation in a cpp file so log.h doesnt have to be in the header.

killerwife pushed a commit to cmangos/mangos-tbc that referenced this pull request Nov 13, 2024
killerwife pushed a commit to cmangos/mangos-classic that referenced this pull request Nov 13, 2024
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.

2 participants