Web Development

General discussion


VB Net is Faster Than C#?

By guoc ·
Our software has several modules with heavy calculation written by VB6. Before migrate to dot net, we would like to find out which is the better language to adapt to. Since most developers prefer C#, the test itself is symbolic. To avoid any side-effect, the test includes pure calculations only. There are no arrays, collections, or strings. The test is conducted using 3 languages, VB6, C# & VBNet. On the main forms of each one, a text box keeps the times of iterations (100000000), other textbox to show the elapsed time, and a command button to execute. I did not use machine frequency or ticker to count time. Here is the VB code written in the click event of the command button.

Dim i As Long
Dim iDiff As Integer iter = CLng(txtIterations.Text)

dA = 10.12
dB = 3.5678
dC = 12.845
DTStart = Now

For i = 1 To iter
dR = dA + dB - dC
dR = dA * dB / dC
dR = dA - dB + dC
dR = dA / dB * dCNext

DTEnd = Now
iDiff = DateDiff("s", DTStart, DTEnd)

txtTimeUsed = iDiff

It is quite easy to duplicate the codes in C# & VBNet where dR, dA, dB, & dC are double with module scope. The variables are declared under samescope in each language.

The results are surprising for this specific test.
C# and VB6 Native Code spent same time to finish the iteration, while VBNet is 2 times faster (spent mush less time) than C# & VB6 both.
Is any one there would like to tell me why? It will be highly appreciated.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

better VB.Net translator

by Jay Eckles In reply to VB Net is Faster Than C#?

Since both C# and VB.Net get translated to MSIL which then gets compiled, I can only assume that the VB.Net translator did a better job in this case of translating high-level language statements to the fewest possible number of MSIL statements.

If it's possible to look at the actual MSIL that is generated for the C# and the VB.Net programs, that might illuminate why there was such a difference in performance.


Related Discussions

Related Forums