Results 1 to 3 of 3

Variant vs Array

Threaded View

  1. #1
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Variant vs Array

    Quick question, for the below, the second loop is faster than the first.

    Is this due to the overhead associated with the Variant type? - Granted it's not much slower though

    Sub DirectArray()
    Dim arr(1 To 10000) As Long
    Dim rngArr
    Dim x As Long
    Dim y As Long
    Dim t As Class1
    
    
    For x = 1 To 10000
        arr(x) = x
    Next x
    
    
    rngArr = Application.Transpose(Sheet2.Range("A1:A10000").Value)
    
    
    Set t = New Class1
    With t
        .StartCounter
        For x = 1 To 10000
            y = rngArr(x) + y
        Next x
        Debug.Print "rngArr: " & .TimeElapsed
        
        y = 0
        
        .StartCounter
        For x = 1 To 10000
            y = arr(x) + y
        Next x
        Debug.Print "arr: " & .TimeElapsed
    End With
    End Sub
    Last edited by Kyle123; 01-26-2012 at 09:50 AM.

Thread Information

Users Browsing this Thread

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

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