Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does debug.print slow execution if code window closed? 2

Status
Not open for further replies.

MasterRacker

New member
Oct 13, 1999
3,343
US
If I leave behind debug.prints in VBA code, will they slow execution if the code editor is not open?

Usually, when I get something working, I comment them out or delete them. Just wondering if I need to bother.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
I suppose it must do something - even printing a variable means the computer has to call the variable, possible convert it to a printable for an output.

It's probably minimal, but I usually do a search for 'debug' when I an about to release an update because it is really annoying if you are working on another bit of code later and get random comments and variables appearing in debug becuase you forgot to remove them last time.

SeeThru
Synergy Connections Ltd - Uk Telemarketing and Telesales Services
and
Synergy Mobile Solutions - UK Mobile phones, land lines and call packages

 
How are ya MasterRacker . . .

Since Debug.Print is used primarily for troubleshooting, you can't really tell until you [blue]rem[/blue] them out! [thumbsup2] ... which you should be doing when your troubleshooting is verified.

Its possible it can have effect as when you print a large amount of listings while in a loop. For the most part [blue]SeeThru[/blue] & [blue]alvechurchdata[/blue] are correct.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm sure they do have an effect, every line of code you write has an effect, that's why you write it, but I wouldn't get too hung up on removing them all unless you find there are speed problems with your system.

The approach I intent to use for my next project is to use debugs temporarily as trouble shooting, but for logging errors and the like use a logging system like log4vba. I've not used it myself yet, so haven't done any analysis, it looks hopeful.

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
I'm not too worried. Just wondering if the Access VBA engine might optimize debug.prints out of the execution plan if the "output device" (code window) is not present.

As I said, I normally comment them out or remove them at some point.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
I'd take it out, if for no other reason that it clutters your code.

Also, it could have an effect, especially if it's inside a loop.
 


Hi,

I often set up complex applications with a TEST or MAINTENANCE procedure. Running this procedure sets a global boolean and other properties that I want for testing or maintenance. I keep my debug.print statements, but enclose them like...
Code:
if bTest then
  debug.print v1, v2, v3
end if


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,
I've done things like that as well.


Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Skip,
Never thought about doing that, I think I will start putting that into my repertoire. Saves a lot of time commenting in/out print statements.

What is interesting about this conversation is no one has consider it is not the amount of debug.prints, but what you are printing.

my debug.prints are usually not simple variables because I can do that in the watch window. Ex.
x = 2
debug.print x
(Unlikely to have any impact)

They are usually inside loops and a complex object/s properties. Which could have a huge difference on performance. Something like.

Do while not rs.eof
...
debug.prints rs.Fields(1) ^ 2 & ": " & rs.fields(n)....
rs.moveNext
loop

Where my rs has 10k records. Two debug.prints with vast impacts differences.
 
MajP,

I've actually gone further. Instead of having to start and run something to go into test mode try this:

Assuming you have a standard FE/BE architecture, At startup look for the existence of "testmode.txt" in the same folder the FE is executing from. If it's there, start in test mode, if not, start in production mode. You can control it without even having to start Access.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
If your debugs are deep inside loops then I can see why you're worried but wrapping them in an [TT]if DebugMode Then ...[/TT] is going to eat processing time regardless of how you decide whether or not you're in debug mode.

Can you do a global search and replace through the project and replace [TT]"Debug.Print"[/TT] with [TT]"Rem Debug.Print"[/TT] in all files?

Geoff Franklin
 
Geoff,
Theoretically yes, in reality no. How much does it cost to check a boolean 10,000,000 times?
Code:
Public Sub testTimer()
  Dim x As Long
  Dim t As Double
  Dim debugMode As Boolean
  t = Timer()
  For x = 1 To 10000000
  
  Next x
  t = Timer() - t
  Debug.Print "Time no check: "; t
  t = Timer()
  For x = 1 To 10000000
    If debugMode Then
     Debug.Print "Some debug"
    End If
  Next x
  t = Timer() - t
  Debug.Print "Time with boolean check: "; t
End Sub
(on an 8 year old dell)

Time no check: 0.125
Time with boolean check: 0.75

A little more than a half second, but that is with 10 million iterations. So if you are looping over a million times (pretty rare for me) then maybe need to be concerned.
 



Wow! Maybe THAT’S the key to answering the “angels dancing on the head of a pin” age-old burning question.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
You may also use a conditional constant (in each module) and play with #If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Just 'cos I couldn't let it lie, I repeated MajP's code, adding in the compiler check:
Code:
Option Explicit

Public Sub testTimer()
  Dim x As Long
  Dim t As Double
  Dim debugMode As Boolean
  t = Timer()
  For x = 1 To 10000000
  
  Next x
  t = Timer() - t
  Debug.Print "Time no check: "; t
  
  t = Timer()
  For x = 1 To 10000000
    If debugMode Then
     Debug.Print "Some debug"
    End If
  Next x
  t = Timer() - t
  Debug.Print "Time with boolean check: "; t
  
  t = Timer()
  For x = 1 To 10000000
    #If TestMode <> 1 Then
     Debug.Print "Some debug"
    #End If
  Next x
  t = Timer() - t
  Debug.Print "Time with Conditional compilation check: "; t
End Sub

Time no check: 0.078125
Time with boolean check: 0.171875
Time with Conditional compilation check: 0.078125



----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
Cool. I did not know you could do conditional compilation in VBA.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
And, to add to the original question, debug.print actually is printing to the immediate window whether or not the window is open.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top