Timestamp function for Lua
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)
Test script:
This script outputs some time measurements with the command ts
.