From: Steve W <lsl BTCONNECT.COM>
>Out of interest what makes up the cost of an exception
>(or more accurately) handling it ?
I just threw together a little project to run with a
profiler
on it. Here's my source code, with the time spent in each
line (including called code) in, I think, milliseconds:
Module Module1
Public Sub main() ' .2
For x As Integer = 1 To 1000000 ' .3
NoException() ' 760,251.0
Try ' 95,687.9
ThrowException() ' 740,076,142.3
Catch ex As Exception ' 9,008,318.4
End Try ' 159,153.4
Next ' 143,069.2
End Sub ' .1
Private Sub NoException() ' 101,932.0
End Sub ' 105,917.2
Private Sub ThrowException() ' 102,454.2
Throw New Exception("Swallowed") '
729,645,784.0
End Sub
End Module
(A large number in the loop is necessary so that the
cost of actually running Sub Main isn't overwhelmed
by the cost of starting and shutting down the app.)
The simple length of the numbers makes a nice logarithmic
histogram...
The big time-eaters (time actually in routine, not including
called routines) are:
WaitForSingleObject 64.8% on 6 million calls
WaitForMultipleObject 24.9% on 6 million calls
Sub ThrowException 4.7% on 1 million calls
SetEvent 2% on 13 million calls
Nothing else got to 1% of CPU time.
===================================
This list is hosted by DevelopMentorŪ http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
|