+ Reply to Thread
Results 1 to 6 of 6

execution speed comparrision

Hybrid View

jakopak execution speed comparrision 10-25-2015, 04:52 PM
walruseggman Re: execution speed... 10-25-2015, 06:14 PM
joeu2004 Re: execution speed... 10-25-2015, 06:32 PM
jakopak Re: execution speed... 10-27-2015, 10:01 AM
Kyle123 Re: execution speed... 10-27-2015, 10:05 AM
joeu2004 Re: execution speed... 10-27-2015, 01:40 PM
  1. #1
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: execution speed comparrision

    Quote Originally Posted by jakopak View Post
    -list can be array of strings or numbers, non empty range of cells
    -array or range is constructed during loop (if condition)
    -things to apply: text size or color, number or string manipulation
    Generally, it is better to iterate once and do as much as possible in each iteration.

    This is especially true if you are modifying cell properties (like formatting).

    Each access to an Excel cell or range is very expensive because it involves "interprocess" (really interthread) communication. Not only does the interprocess communication take a lot more time than a VBA function call, for example, but also it involves a process context switch, which allows other processes on the computer to take control of the CPU.

    (The context switch issue might be less of a concern with modern multiple-core computers. I still use a single-core single-CPU computer. But the interprocess communication overhead is still an issue.)

    For that reason, if you are manipulating cell values, not properties, it is usually best to read a range into a VBA variable, do all the manipulation, then write the VBA variable out to the Excel range. For example:
    Dim v As Variant, r As Long, c As Long
    v = Range("A1:Z1000")
    For r = 1 To 1000: For c = 1 To 26
        .... access v(r,c) ....
    Next c, r
    Range("A1:Z1000") = v
    That said, there are situations where it might be better to iterate on each VBA array separately, namely: if you have very large VBA arrays, each with many thousands of elements that you are accessing sequentially.

    In that case, the benefit of iterating each VBA array separately arises from the "locality" of VBA address references. Each time you access a single element in a VBA array, the CPU actually loads many neighboring elements into the cache as well, which takes some amount of time. If the next reference is to a neighboring array element that is already in the cache, it is faster for the CPU to access it.

    Usually, I do not lose sleep over "cache optimization". But I have encountered situations where that makes a significant difference in overall performance.
    Last edited by joeu2004; 10-25-2015 at 06:35 PM. Reason: minor code change

  2. #2
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: execution speed comparrision

    Joeu2004, thank you very much. Excellent answer I hopped for.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Speed up this macros execution
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2015, 01:58 AM
  2. Want to Speed Up Code Execution
    By PosseJohn in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-28-2013, 07:34 PM
  3. Execution speed of macros
    By JM967 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2013, 02:43 PM
  4. [SOLVED] Execution Speed of VBA Code
    By sdelaney7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-17-2012, 08:35 PM
  5. how to speed up macro code execution?
    By sharmanjali87 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2010, 06:45 AM
  6. Speed up Excel execution
    By Sinus Log in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2005, 01:10 AM
  7. [SOLVED] code execution speed question
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2005, 05:05 PM

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