Forum > Games
Measure code execution and convert the result to milliseconds
mika:
--- Quote from: furious programming on November 01, 2022, 12:03:59 pm ---i.e. the long processing of SDL events and the times that increase with the increase of the intervals between measurements, and not on the implementation of the main game loop, which I have not shown here at all.
--- End quote ---
Agree and culprit is:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SDL_PumpEvents();Longer interval in between calls - longer execution of mentioned procedure. It seams that there is upper limit, but in case of event accruing execution is even longer.
Jorg3000:
Hi!
--- Quote ---Sometimes the sample jump up to several hundred or several thousand cycles.
--- End quote ---
Could it simply be that the CPU core has processed another thread in between?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Windows.SetPriorityClass(Windows.GetCurrentProcess(),HIGH_PRIORITY_CLASS); // REALTIME_PRIORITY_CLASS
Actually you should measure it using REALTIME_PRIORITY_CLASS, but that is only available as admin, I think.
Jörg
furious programming:
@mika: SDL_PumpEvents should not be used if the events are being pulled from the queue using SDL_PollEvent. All because SDL_PollEvent can call SDL_PumpEvents internally. But even if I remove it and leave only the loop, reading the events is still time consuming and continues to fluctuate as the interval between measurements increases. So removing SDL_PumpEvents fixes almost nothing, because the time gain is microscopic:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---time: 0.090ms | sample: 899time: 0.231ms | sample: 2313time: 0.090ms | sample: 898time: 0.090ms | sample: 903time: 0.321ms | sample: 3206time: 0.090ms | sample: 896time: 0.089ms | sample: 893time: 0.071ms | sample: 708time: 0.089ms | sample: 892time: 0.090ms | sample: 899time: 0.191ms | sample: 1911time: 0.077ms | sample: 767time: 0.610ms | sample: 6099time: 0.089ms | sample: 894time: 0.072ms | sample: 716time: 0.091ms | sample: 912time: 0.091ms | sample: 906time: 0.070ms | sample: 700time: 0.094ms | sample: 943time: 0.074ms | sample: 739time: 0.100ms | sample: 1003time: 0.651ms | sample: 6509time: 0.098ms | sample: 975time: 0.765ms | sample: 7652time: 0.354ms | sample: 3535
As you can see, processing an ~empty queue still takes up to half a millisecond (with SDL_Delay(10) between frames/measurements), and when I move the cursor over the window quickly (for example, making a circles), it takes up to two milliseconds to get events out of the queue, which is ridiculous. There is a hidden problem, and I don't know where exaclty. This test program is too simple to make such a terrible bugs (still I don't see any).
@Jorg3000: I don't want to use platform specific functions — the game code must be cross-platform, that's why I'm using SDL functions only. Anyway, using the administrator's rights and setting the "real time" priority does not change anything.
Paul_:
--- Quote from: furious programming on November 01, 2022, 12:03:59 pm ---
What I just mentioned is not a game loop .. and not on the implementation of the main game loop, which I have not shown here at all
--- End quote ---
I didn't mention "game loop" anywhere. There is repeat while loop in the code above. Therefore, I wrote about the loop.
--- Quote ---Secondly, the use of SDL_Delay (internally: Sleep on Windows) is the only available solution that allows you to create gaps between frames without using spinlocks (busy waiting)
--- End quote ---
This is rather a dead end if you want to use vsync for example. There are a number of techniques that can be combined in various ways and where Sleep() is not used - https://dewitters.com/dewitters-gameloop/, https://gafferongames.com/post/fix_your_timestep/ but I assume you've seen it before.
SDL2 - SDL_Delay() issues - https://discourse.libsdl.org/t/sdl-delay-accuracy-question/20458/4 (still actual, I guess)
mika:
@furious programming you cannot get rid of SDL_PumpEvents. If you use SDL_PollEvent, then it will call SDL_PumpEvents for you. I only confirmed that there is a problem. You have to find solution.
For me maximal time for SDL_PumpEvents was 1ms and with event 3ms. Still possible achieve decent frame rates. You cannot expect constant execution time for any code, especially, when measurement interval is small. 1ms is small interval.
Navigation
[0] Message Index
[#] Next page
[*] Previous page