Consulting

Results 1 to 5 of 5

Thread: Any Extra Execution Time?

  1. #1

    Any Extra Execution Time?

    Is there any significant cost in execution time (or anything else) to Call a small procedure (say, 10 lines) rather than imbed the called code in-line in the main procedure?
    Does the compilation pre-find the location of the called procedure, or does that have to be done at runtime?
    Is it any more expensive to Call a procedure in Personal.xls than it is to call the same procedure located in the same workbook? I've wondered about that.

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Cyber,

    Offhand - dunno. Why don't you time it? (you'll need to run a few times and average out the results)


    Option Explicit
     
    Sub TimeIt()
    Dim StartTime#, FinishTime#, N&
    StartTime = Timer
    'put your own code below (example given)
    For N = 1 To 100
    [A1] = N
    Next
    FinishTime = Timer
    MsgBox "Total Time = " & FinishTime - StartTime
    End Sub
    Pre-finding depends on whether you have Background Compile checked or not (if it's checked it may only be 'found' during run-time)...For a bit more about this, check this out

    HTH,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Thanx for the suggestion, John. The only reason I haven't done a test is that I'm not sure I could do a valid one that excludes other factors (unknown to me) that might skew the results. Maybe I'll try it anyway. I was hoping that the answers were widely known by the experts. I know that John Walkenbach has run some timing tests on other things and reported on them in his books, but this topic wasn't covered. Just thought I'd ask. Thanx again.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Cyberdude
    The only reason I haven't done a test is that I'm not sure I could do a valid one that excludes other factors (unknown to me) that might skew the results.
    That is why you would repeat the test, in both situations, a set number of times, and average the results out. It doesn't remove the other factors, but it does smooth it somewhat.

    If you want a hi-res timer, Karl Peterson does a beaut at http://vb.mvps.org/tools/ccrpTmr/
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    FYI,

    One thing to watch out for when you're timing code is messageboxes and inputboxes. Anything that ask the user for an input CAN significantly skew the results.

    Whenever I time a proc, I always comment msgbox and inputbox areas, and put in some code to set any required variables to eliminate this problem.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •