Anonymous
729 Views, 3 Replies
05-12-2020
03:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-12-2020
03:37 AM
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![]()
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.
Solved! Go to Solution.