Get elapsed time independently of time spent debugging?

Issue

This Content is from Stack Overflow. Question asked by aybe

This is a fairly simple problem for which I’m trying to find a solution for, when debugging a time-based loop on a game, the time spent while debugging is reflected on the total elapsed time.

If I hit a breakpoint and spend 10 minutes debugging, when querying for the elapsed time, it will of course have advanced by 10 minutes as well and that makes it really unpractical for debugging.

The function to get the elapsed time is nothing short of than this:

private static int GetElapsedTime()
{
    var time = (int)(GLFW.GetTime() * 1000.0);

    return time;
}

Basically what I’m looking for is, just like how retrieving time works in Unity, it does not matter how long you spend stepping through your code, when you get elapsed time, it will only have advanced by some discrete time step and not by the real time you’ve spent debugging.

In Unity, there are two properties to retrieve the elapsed time: Time.realtimeSinceStartup and Time.time. The behavior I’m currently getting is like the former, what I’m looking for is for the latter instead.

I tried playing a bit with Debugger.IsAttached and try come up with a solution but without much luck.

And obviously, I am not using Unity, hence the question.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?