I did a little benchmarking with vb.net and C#. Its nothing big, just a simple for loop iterating 1 billion times. The code is below.
I noticed something interesting. If I put the variable declarations inside the button_click method, it adds at least 2 seconds to the time it takes the loop to complete, but if they are declared above the contructor, those 2 seconds are shaved off.
VB.NET Version
VB Code:
Option Explicit On
Imports System
Public Class Form1
Inherits System.Windows.Forms.Form
Dim num As Long = 1000000000
Dim dt As DateTime
Dim ts As TimeSpan
Dim timeNow As String = ""
Dim i As Long
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
I didnt look at the code or anything. But I was just wondering if you tried the test several times or not, because it might give you different results each time.
Any ways, C# is SLIGHLY faster than VB.NET
this might be intersting for some of you guys:
C# code might run slightly faster in a few circumstances; for example, the C# compilter generates code
that reclaims the memory used by objects more aggressively than under Visual Basic. However, most of the
time the difference in the performance won't be greater than 5 percent, so it's hardly an argument for
selecting one language over the other.
(from Programming Microsoft Visual Basic.Net)
maybe it has to do something with memory stuff that he says
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
I wonder if the backward compatibility of VB code that VBdN can use factors into it's slightly slower performance; even if a VB6 style syntax is not used. Even if C# is less than 5% faster on a benchmark test, it's still pretty impressive for VB, considering the total make over it got. C# is a great language, but I have yet to see a significant number of companies looking to totally rewrite a VB app just to use C# (with the exception of ASP to ASP.NET in which you have to re-write regardless). The company I work for has a VB app with roughly 3 Million lines of code that has been written over a course of 7 years in the various releases of VB. A rewrite of our main revenue producing app in C# would probably put us out of business. That 5% decrease is, IMO, pretty easy to live with considering 99% of our processes requiring optimum speed performance are going to be on a server.