In a previous posting in this thread I reported that
if(DEBUG)
win.debug(...)
is about 15x faster than calling a script, i.e.,
[EMAIL PROTECTED]()
and that writing a log/debug plugin wouldn't be faster -in fact, about
20% slower in an admittedly poor simulation based on win.hex()
I still wanted to improve if(DEBUG), so I came up with the following
scheme
if( select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1)>0 )
win.debug(...)
which has significant advantages over the simpler if(DEBUG), and it's
only 14% slower on my PC both while debugging and in a production script
(test results below).
So, I will start experimenting this scheme in my scripts.
Advantages:
-----------
1) significantly faster than a debug script and as fast as a plugin
2) flexible, can write anything you want in do-endif body
(win.debug, file.writeall, .myScript ...)
3) self-contained, no need for plugins or scripts that users
may not have or want to install
4) works with all powerpro versions
5) allows for setting a debug level and changing it dynamically
6) production script works unchanged (with no debugging output)
on other users' PCs
7) releasing a script doesn't need extra work to eliminate
debugging code
7) other users can easily turn on debugging output if needed
How does it work?
-----------------
When you're developing a script and you want to add debugging output,
use the following lines:
if( select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1) > 0 )do
win.debug("whatever you want goes here")
endif
To enable debugging output for script "MyScript.powerpro"
ADD the following string to GLOBAL variable gvDebugLevel:
N ++ "MyScript"
N is a number between 0 and 9, i.e.,
"2MyScript"
sets debugging level 2 for script "MyScript.powerpro".
To disable debugging output for "MyScript.powerpro" either
remove its entry from gvDebugLevel or set N=0, i.e.,
"" or "0MyScript"
if gvDebugLevel already includes other words, you will need to include
word separators, spaces should be fine -- unless your scriptnames include
spaces themselves, in which case you might experience false positives.
"1ScriptA 2MyScript"
Your scripts can take advantage of debugging levels by writing more
debugging output as the level increases, for instance,
if (select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1) >0 )do
win.debug("entering "++scriptname)
if select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1) >1)do
win.debug(scriptname++" arguments: <"++arg(1)++"> <"++arg(2)++">")
endif
endif
The two if lines above differ only in the >0 or >1 test they perform.
Extensions and other possible schemes:
--------------------------------------
scriptname can just as easily be any ID, like "@ThisLabel" etc.
for finer selection of the object being debugged.
if( select(remove(gvDebugLevels,index(gvDebugLevels,"@ThisLabel")-2),1,1) > 0
)do
A global map variable is an alternative to a global string variable.
I prefer the string because it doesn't need a call to a plugin, and
because it doesn't need to be created, whereas the map must be created
even when it isn't needed.
Test results:
-------------
delta=5
C: drive
debug window open, minimized, unpaused
now: local DEBUG=1 then 0
if(DEBUG>0)do
new: local gvDebugLevels="1"++scriptname then ""
if( select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1)>0
)do
now new now new
prod debug prod debug
---- ---- ---- ----
3789 3515 2023 1764 run 1
3739 3009 1787 1636 run 2
4094 3034 1766 1538 run 3
3761 3448 1600 1380 run 4
3309 3428 1453 1311 run 5
---- ---- ---- ----
3763 3303 1718 1518 average discarding min and max
---- ---- ---- ----
100% 114% 100% 113% new/now
Test code
---------
@performance_test
local delta=5
local i,t0,t1
local j=0
local e=vec.create(20)
local DEBUG=0
t1=timesec+delta
i=0
for(t0=timesec;t0<t1;t0=timesec)
i=i+1
if(DEBUG>0)do
win.debug(i)
endif
endfor
e[j]="[NOW PRODUCTION]if(DEBUG>0)win.debug() "++i
j=j+1
local gvDebugLevels=""
t1=timesec+delta
i=0
for(t0=timesec;t0<t1;t0=timesec)
i=i+1
if( select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1)>0 )do
win.debug(i)
endif
endfor
e[j]="[NEW SCHEME PRODUCTION]if(expr>0)win.debug() "++i
j=j+1
local DEBUG=1
t1=timesec+delta
i=0
for(t0=timesec;t0<t1;t0=timesec)
i=i+1
if(DEBUG>0)do
win.debug(i)
endif
endfor
e[j]="[NOW DEBUGGING]if(DEBUG>0)win.debug() "++i
j=j+1
local gvDebugLevels="1"++scriptname
t1=timesec+delta
i=0
for(t0=timesec;t0<t1;t0=timesec)
i=i+1
if( select(remove(gvDebugLevels,index(gvDebugLevels,scriptname)-2),1,1)>0 )do
win.debug(i)
endif
endfor
e[j]="[NEW SCHEME DEBUGGING]if(expr>0)win.debug() "++i
j=j+1
t0=e[0]
for(i=1;i<vec.length(e);i=i+1)
t0=t0++" "++e[i]
endfor
win.debug(t0)
messagebox("ok",t0)
quit
On 31-Aug-2005 I wrote:
Fastest method for production scripts (unpaused debug window):
static DEBUG=0
if(DEBUG)
win.debug(...)
which is 15x faster than calling a script label (5776/377=15 5899/379=15)
Calling a log plugin (simulated with win.hex(0) paused debug window)
wouldn't be faster, in fact about ~20% slower (5673/3971=1.2 5749/4003=1.2)
currently, pausing the debug window yields a ~2x speed improvement.
------------------------ Yahoo! Groups Sponsor --------------------~-->
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/JV_rlB/TM
--------------------------------------------------------------------~->
Attention: PowerPro's Web site has moved: http://www.ppro.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/power-pro/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/