G
Guest
I am creating a new VB.Net Windows App project in VS 2005 and VS 2003 and
copying the code below into the Form1 class. If I compile as Release, and
run, I am seeing this app when run under .Net 2.0 (VS 2005) performing 3-4
times slower than the one compiled under .Net 1.1 SP 1 (VS 2003). Is there a
performance loss in .Net 2.0 for concurrent threads or the Interlocked
functionality?
Private Const MainLoopIterations As Long = 100L
Private Const ThreadIterations As Long = 1000000L
Private _ds, _de As DateTime
Private _total As Long
Private _lockObj As New Object
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
RunTest()
End Sub
Private Sub RunTest()
_total = MainLoopIterations * ThreadIterations
_ds = DateTime.Now
For i As Integer = 1 To MainLoopIterations
ThreadPool.QueueUserWorkItem(AddressOf ThreadTestProcess, Nothing)
Next
End Sub
Private Sub ThreadTestProcess(ByVal state As Object)
For i As Integer = 1 To ThreadIterations
If Interlocked.Decrement(_total) = 0 Then
_de = DateTime.Now
Me.BeginInvoke(New EventHandler(AddressOf TestDone))
End If
Next
End Sub
Private Sub TestDone(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Total time (ms): " +
_de.Subtract(_ds).TotalMilliseconds.ToString())
End Sub
copying the code below into the Form1 class. If I compile as Release, and
run, I am seeing this app when run under .Net 2.0 (VS 2005) performing 3-4
times slower than the one compiled under .Net 1.1 SP 1 (VS 2003). Is there a
performance loss in .Net 2.0 for concurrent threads or the Interlocked
functionality?
Private Const MainLoopIterations As Long = 100L
Private Const ThreadIterations As Long = 1000000L
Private _ds, _de As DateTime
Private _total As Long
Private _lockObj As New Object
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
RunTest()
End Sub
Private Sub RunTest()
_total = MainLoopIterations * ThreadIterations
_ds = DateTime.Now
For i As Integer = 1 To MainLoopIterations
ThreadPool.QueueUserWorkItem(AddressOf ThreadTestProcess, Nothing)
Next
End Sub
Private Sub ThreadTestProcess(ByVal state As Object)
For i As Integer = 1 To ThreadIterations
If Interlocked.Decrement(_total) = 0 Then
_de = DateTime.Now
Me.BeginInvoke(New EventHandler(AddressOf TestDone))
End If
Next
End Sub
Private Sub TestDone(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Total time (ms): " +
_de.Subtract(_ds).TotalMilliseconds.ToString())
End Sub