ID:2090169
 
Just coded this for our Master Controller to more properly calculate how long the process it calls runs for, so we can display this to admins and other wise programmatically track their timing.

//fancy math for calculating cost in ms from tick_usage percentage and the length of ticks
//percent_of_tick_used * (ticklag * 100(to convert to ms)) / 100(percent ratio)
//collapsed to percent_of_tick_used * tick_lag
#define TICK_USAGE_TO_MS(percent_of_tick_used) (percent_of_tick_used * world.tick_lag)


Limitations:

Doesn't work on timing anything that sleeps mid run or runs for more than like 2 ticks or so (at some point it seems to reset even if no new tick happens)
Doesn't work when the proc chain was started by certain user interactions (like set instant = 1 verbs and movement verbs and maybe mouse procs, not sure)
It's accuracy is about a few ms, depending on unknown factors
you might even say it's prescient