Skip to content

Timestamp function for Lua

Hannu Hanhi requested to merge Hannu_Hanhi/SRB2:lua-timestamp into next

Adds getTimeMicros, a profiling timer function, to Lua. Two values returned from the function can be subtracted from each other to find how much time (in microseconds) is between them. This can be used to measure the performance of Lua code.

The function shouldn't be used for anything else than performance measurements, it's not synced and it will wrap around the 32-bit integer limit once in about every 72 minutes.

The implementation was put into lua_baselib.c. Tell me if there is a better place for it.

Warning about OpenGL and HUD hooks: measuring Lua API calls that contain OpenGL API calls can give unreliable/confusing results because of the asynchronous nature of OpenGL. This applies to measuring HUD drawing functions in OpenGL mode. More about this: https://www.khronos.org/opengl/wiki/Synchronization and https://www.khronos.org/opengl/wiki/Performance (Also this applies to many perfstats rendering measurements in OpenGL mode)

Short version of warning: Don't trust (or be very very careful with) measurements of code that draws to the HUD when in OpenGL mode.

Test build: (based on next so be careful with your save files)

srb2win_lua-timestamp2.exe

Test script:

timestamptest2.lua

This script outputs some time measurements with the command ts.

Edited by Hannu Hanhi

Merge request reports

Loading