NWNX Timer Plugin Documentation
This plugin implements a simple, yet highly accurate timer. Perfect for knowing how long your functions really take to execute.
1) Import the include file
Import nwnx_time.erf into your module and include this file in every script where you want to call the timer functions:
2) Measure times
To measure times, call the StartTimer function, do something which takes a bit of time, and then call the StopTimer function. Here is an example:
object oModule = GetModule();
for (i=0; i<500; i++)
j = i*2;
elapsed = StopTimer(oModule, "MyTimer");
WriteTimestampedLogEntry("The loop took " + elapsed + " microseconds to complete.");
In nwserverlog.txt you will find something like this:
The loop took 249 microseconds to complete.
xp_time.txt (in NWNX installation directory) will look like this:
NWNX Timer Plugin V.0.0.1
(c) 2006 by Ingmar Stieger (Papillon)
visit us at http://www.nwnx.org
* Plugin initialized.
o Starting timer MyTimer0
o Stopping timer MyTimer0: 249Ás / 0.249 msec / 0.000 sec
4) Technical background info
The Timer plugin uses functions provided by the operating system (e.g. QueryPerformanceCounter) to store a timestamp when StartTimer is called. When StopTimer is called, it takes the current timestamp and computes the difference between both. You can let a timer run a long as you want, without taking a performance hit or costing lag.