[REBOL] Re: idea for pre-processing
From: sunandadh:aol at: 20-Jun-2002 13:51
Anton:
> I want to optionally strip debugging lines in my
> programs, so that they run at top speed without
> them. There will be no overhead of, eg:
>
> if debug [print "inner loop"]
>
> which could occur multiple times in a program,
> and within tight, inner loops, impacting
> performance.
> Has anyone done something like this?
Here's something I picked up off this list a year or so ago. Put this in the
User.r or initialisation code:
either system/user/email = _my-email-address_ ;;; or some such test/prod
test
[d-print: :print]
[d-print: func [whatever [any-type!]] [] ]
That defines d-print as either 'print or nothing. Debugging code can then
stay in:
d-print "inner loop"
It doesn't _quite_ give you top speed as 'd-print will be evaluated -- here's
a test of the overhead:
d-print: func [whatever [any-type!]] []
loops: 100000000
Start-time: now/time/precise
loop loops [d-print "inner-loop"]
print ["d-print test " now/time/precise - start-time]
Start-time: now/time/precise
loop loops []
print ["null loop " now/time/precise - start-time]
Results on my machine:
d-print test 0:00:39.82
null loop 0:00:02.85
Other uses: I have system where d-print is turned on/off if an obscure button
is right-clicked when an input field contains an unlikely value. That's
invaluable for over-the-phone debugging.
Sunanda.