Select to view content in your preferred language

C# vs VB.NET. Perfomance

826
3
04-04-2010 01:21 AM
DenisT
by
Deactivated User
Why there is so big difference in C# / VB.NET perfomance?
There was a session at devsummit 2010. There is a presentation, sources of the benchmark. The benchmark measured ShapeCopy operation.
VB.NET is 30 times (!!!) faster then C#. Not 5-10-30%, but 30 times!
Why?
Should we prefer VB.NET to write applications using ArcObjects?
Is it possible to get the same perfomance using C#?
0 Kudos
3 Replies
DenisT
by
Deactivated User
As an ArcObjects developer, this means that if your application is not initialized as a single threaded application, the .NET framework will create a special single threaded apartment (STA) thread for all ArcObjects since they are marked as STA. This will cause a thread switch to this thread on each call from the application to ArcObjects. In turn, this forces the ArcObjects components to marshall each call, and eventually it may be about 50 times slower for a call to the COM component. Fortunately, this can be avoided by simply marking the main function as [STAThread].

http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/2c2d2655-a208-4902-bf4d-b37a1de120de.htm

🙂
Tested. Everything is fine now, the perfomance is just the same.
MarkCederholm
Frequent Contributor
Excellent!  Thanks for finding that out.  It was my assumption all along that their performance should be the same, and I was shocked when the benchmark turned out otherwise.  I'm going to look into whether this is also the reason behind crappy C++/CLI performance.

Update:  Never mind my last update.  I've brought VB in line with C# and F#, and C++/CLI (unmanaged) is in line with C++/ATL.
0 Kudos
DenisT
by
Deactivated User
Thank you for your session, Mark. Very interesting! I wasn't there, at Palm Springs, and there is no video (maybe later?), but I've read the presentation - very cool.

P.S. Sorry for my English.
0 Kudos