Thread: GetTime()
View Single Post
10-03-20, 03:01 AM   #15
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Originally Posted by KL1SK View Post
If I understood correctly "Debug profiling" works constantly. debugprofilestop () just returns its running time?
debugprofilestop() returns the number of milliseconds since the last time debugprofilestart() was called. The value is undefined if the later has never been called, but seems to tick at the same rate anyway.

The idea of these two functions is a misnomer. There isn't some "profiling" code behind them. One stores the current time in memory and the other compares that with the current time.



Originally Posted by KL1SK View Post
thanks for xpcall, never used such a useful feature before . And also does not eat up performance.
xpcall() and pcall() makes the function given run in protected mode, which means any errors encountered returns to the caller. It's useful in code like event handlers and callback libraries that need to run a list of registered functions, any of which will cause cascading problems if an unprotected error occurs. xpcall() lets you specify a custom error handler to run, however I just pipe in the existing one so it still gets the proper call stack in the debug data.



Originally Posted by KL1SK View Post
I decided to abandon OnUpdate in favor of C_Timer, it turned out to be a little cheaper. In addition to this, you can run multiple loops in parallel and they work great. Possibly the engine runs them in different threads, since the load does not grow proportionally.
Lua is a single-threaded environment, meaning it doesn't support true asynchronous threads. OnUpdate guarantees that a frame goes out in between each time the function runs. C_Timer on the other hand adds the function to an internal scheduler that tries to run the function as close to the given time as it can when the engine isn't busy. It is capable of running multiple times in between two frames, so it isn't as reliable in limiting how often a function is run, especially when given very short delays.

A general rule of thumb I follow. OnUpdate when you have a long task that you need to spread out over time. C_Timer when you have a small task that needs to be repeated, but not as frequent.



Originally Posted by KL1SK View Post
I was considering using 'coroutine'. But does it have any advantages other than convenience?
It's just personal preference. Coroutines can be very powerful if you know how to use them. Realistically, I've never really needed them.

What a coroutine does is lets you pause execution of its assigned function and resume it later. Its more specialized use is for multi-stage functions that have a list of multiple heavy purpose tasks you want to spread over time.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-03-20 at 03:06 AM.
  Reply With Quote