Debug â
Debug is a powerful module for measuring performance in your scripts.
st.debug.performance() â
A function to measure the execution time of a callback function.
Syntax â
lua
st.debug.performance(title, cb)
Parameters â
title
: string
A title describing this measurement.
cb
: function
The function to be executed and measured.
Return value â
Type: varies
Returns the result(s) of the callback function.
Example â
lua
local result = st.debug.performance("MyFunction", function()
local sum = 0
for i = 1, 100000 do
sum = sum + i
end
return sum
end)
print(result)
-- Expected output: Performance: MyFunction -> {elapsed time} Ξs
st.debug.performanceStart() â
A function to start a performance measurement with a unique identifier.
Syntax â
lua
st.debug.performanceStart(title)
Parameters â
title
: string Optional
An optional title describing this measurement.
Return value â
Type: string
Returns the auto-generated ID to be used in
performanceStop()
.
Example â
lua
local id = st.debug.performanceStart("Loop Execution")
-- Some heavy computation here
st.debug.performanceStop() â
A function to stop a previously started performance measurement.
Syntax â
lua
st.debug.performanceStop(id)
Parameters â
id
: string
The unique ID returned by
performanceStart()
.
Return value â
Type: number
Returns the elapsed time in microseconds.
Example â
lua
local id = st.debug.performanceStart("Loop Execution")
for i = 1, 50000 do
local x = i * 2
end
local elapsed = st.debug.performanceStop(id)
print("Execution time:", elapsed, "Ξs")
-- Expected output: Performance: Loop Execution -> {elapsed time} Ξs