I'm working in dm-script and need to measure the execution time of various functions. Currently, I use the following pattern to measure time:
Number time1, time2
time1 = GetCurrentTime()
// run some function
time2 = GetCurrentTime()
Result(CalcTimeUnitsBetween(time1, time2, 1) + "\n")
I would like to encapsulate this behavior into a reusable function that accepts another function (by its name) as an input parameter. For example, I attempted the following:
Void time_elapse(function_name)
{
Number time1, time2
time1 = GetCurrentTime()
function_name()
time2 = GetCurrentTime()
Result(CalcTimeUnitsBetween(time1, time2, 1) + "\n")
}
However, I'm not sure if passing a function as a parameter in this way is supported in dm-script, or if there is a better approach.
What I've Tried:
- I created a time_elapse function that accepts a function name and then measures the time taken by that function.
- I looked for documentation or examples of passing functions as parameters in dm-script, but haven’t found a clear solution.
Questions:
- Is it possible to pass a function as a parameter to another function in dm-script, as shown above?
- If not, what are alternative methods to achieve a reusable timing mechanism for different functions?
Any insights or alternative approaches would be appreciated.