I was too quick. The expression I posted earlier incorrectly matched
substrings, so you'd get the wrong
result if you had, say, "myscript" and "myscript2". I'm reposting the corrected
article here, disregard the
previous one. With this fix in place, the method is 20% slower than a simple
if(DEBUG). That's on a par
with a plugin (rough figures), so for me it's still worth using.
--- corrected article ---
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 (mind line wraps):
if( select(remove("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++scriptname++" ")-2),1,1) >
0)do
win.debug(...)
endif
which has significant advantages over the simpler if(DEBUG), and it's
just 20% slower for a production script, that is roughly as
slow as calling a plugin - on my PC, 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 (and there's no debug output)
on other users' PCs
7) releasing a script doesn't need extra work to eliminate
debug code
7) other users can easily turn on debug output if needed
How does it work?
-----------------
When you're developing a script and you want to add debug output,
use the following lines:
if( select(remove("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++scriptname++" ")-2),1,1) >
0)do
win.debug("whatever you want goes here")
endif
To enable debug 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.,
"2 myscript" (all LOWERcase)
sets debug level 2 for script "MyScript.powerpro".
To disable debug output for "MyScript.powerpro" either
remove its entry from gvDebugLevel or set N=0, i.e.,
"" or "0 myscript"
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.
"1 scripta 2 myscript"
Debug levels are single-digit numbers in the range 0-9.
Your scripts can take advantage of debug levels by writing more
debug output as the level increases, for instance,
if( select(remove("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++scriptname++" ")-2),1,1) >
0 )do
win.debug("entering "++scriptname)
if( select(remove("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++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("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++"@ThisLabel"++" ")-
2),1,1) > 0 )do
where global gvDebugLevel="1 @ThisLabel"
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("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++scriptname++" ")-
2),1,1) > 0)do
now new now new
prod prod debug debug
---- ---- ---- ----
3942 3126 1319 1165 run 1
3503 2978 1390 1184 run 2
3575 3120 1469 1274 run 3
3958 2654 1588 1370 run 4
3309 3187 1689 1415 run 5
---- ---- ---- ----
3673 3075 1482 1276 average discarding min and max
---- ---- ---- ----
100% 119% 100% 116% 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("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++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("0 "++gvDebugLevels,index("0 "++gvDebugLevels++" 0","
"++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 --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/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/