Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
729 Views, 3 Replies

Performance VBA vs .NET

I am seeing a huge difference in the performance between VBA and .NET.

A code that executes in under a second in VBA takes more than 65 seconds in .NET:thinking_face:

 

VBA: (<0.5 sec)

 Sub testperformance()
    Dim ElapsedTime As Long:   ElapsedTime = Timer
    Dim oPartDoc As PartDocument: Set oPartDoc = ThisApplication.ActiveDocument
    Dim oPartDef As PartComponentDefinition: Set oPartDef = oPartDoc.ComponentDefinition
    Dim nCylinders As Integer
    
    Dim oSurfBody As SurfaceBody
    Dim oFace As Face

    For Each oSurfBody In oPartDef.SurfaceBodies
        For Each oFace In oSurfBody.faces
            If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                nCylinders = nCylinders + 1
            End If
        Next
    Next
    MsgBox Timer - ElapsedTime
End Sub

 

.NET: (> 65 sec)

 Sub testperformance()
        Dim ThisApplication As Application = GetObject(, "Inventor.application")

        Dim start_time As DateTime = Now
        Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
        Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim nCylinders As Int16 = 0

        For Each oSurfBody As SurfaceBody In oPartDef.SurfaceBodies
            For Each oFace As Face In oSurfBody.Faces
                If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                    nCylinders += 1
                End If
            Next
        Next

        Dim elapsed_time As TimeSpan = Now.Subtract(start_time)
        MsgBox(elapsed_time.TotalSeconds)
    End Sub
End Class

 

Code is run on a complex part file with approx 10.000 faces.