+ Reply to Thread
Results 1 to 6 of 6

Which call method is the fastest?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Question Which call method is the fastest?

    Which call method is fastest?

    Method 1
    Please Login or Register  to view this content.

    Method 2
    Please Login or Register  to view this content.
    Method 3
    Please Login or Register  to view this content.
    (If there is a speed difference but the difference is negligible then, just for the sake of the argument, imagine the code is running on a very slow computer).

    Also apart from code appearance & speed difference (if any) are there any pros/cons to any of these methods?
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Which call method is the fastest?

    Hi,

    I prefer to see Method 1 of Call Macro2.

    If you have some crazy name macro like DoThisNow and you don't use the "Call" then it isn't obvious if it is a Macro you are running or some built in VBA thing.

    I believe if you use Method 3 it will need to parse the string and find it in the list of macros and therefore take a little bit longer.

    If I try to read my code after a few months or read others code I find the Call Macro syntax much more readable.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Which call method is the fastest?

    Thanks Marvin for the quick reply.

    Quote Originally Posted by MarvinP View Post
    I prefer to see Method 1 of Call Macro2. If you have some crazy name macro like DoThisNow and you don't use the "Call" then it isn't obvious if it is a Macro you are running or some built in VBA thing.
    Agree on both points. But I am willing to switch methods if Method 2 or 3 is superior.

    Quote Originally Posted by MarvinP View Post
    I believe if you use Method 3 it will need to parse the string and find it in the list of macros and therefore take a little bit longer.
    I have that theory too but I am looking for something to back that up... Which is why I started this thread.

    Can anyone confirm/deny our theory re the speed issue with Method 3?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Which call method is the fastest?

    Hey,

    My signature line is "One test is worth a thousand opinions".

    It seems to me you should create two macros. The first uses method 1 and you should call your macro2 that is a simple return. Put a for.. next loop in Macro 1 and a timer and run the call to Macro 2 1000 times. Then change it to method 2 and run it again. Then for method 3.

    PLEASE let us know the results.....

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Which call method is the fastest?

    Something like?
    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Which call method is the fastest?

    Quote Originally Posted by MarvinP View Post
    "One test is worth a thousand opinions".
    Too True

    Quote Originally Posted by MarvinP View Post
    PLEASE let us know the results.....
    See test code at the bottom of this post. (I decided to use 50,000 loops. 1000 wasn't enough to show up any real difference).

    My results were:
    method 1 = .172 seconds
    method 2 = .109 seconds
    method 3 = 8.219 seconds

    Results will vary by computer performance of course.

    My conclusion:
    • Method 1 is superior as it is fast & it is is the easiest to read .
    • The speed difference between 1 & 2 really is negligible. (Remember I am talking about 50,000 loops here. If you set it to say 1000 then there is no recordable difference between 1 & 2)
    • Method 3 is clearly the worst in terms of speed (And the result shown here is an optimal result - I tested it in an new XLSM. My theory is that the more macros you have in a project, the more procedures VBA will need to search in order to find the macro to run and the slower method 3 will become).

    Please Login or Register  to view this content.

    P.S. I remember now why I used to use Application.Run. Unlike Call, Application.Run has the ability to call a module level sub in a different module. (But then again - either make the sub you are calling project level or move the sub to where you really need it )
    Last edited by mc84excel; 03-27-2013 at 11:24 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1