Exceptionally fast

scale is in seconds
time scale is in seconds

This is the result of a test I did with some very stupid code to test the speed of exceptions. We sometimes hear that exceptions are slow and I wondered how much the stack depth affects the result. I used very simple code that recursed if the level of recursion was less than a threshold and threw an empty ApplicationException when the threshold was reached. The test was repeated one thousand times and the results are graphed above.

The verdict? Well – as you might expect – the answer is : it depends on what you mean by slow!
i think that the really slow exceptions are ones that occur as a result of a problem with COM or p/invoke or ones that are marshalled across remoting or AppDomain boundaries. I’d like to do something with recursed AppDomains as that could be really painful.
PS: apologies for the image, I am simply too lazy to figure out how to make it display properly. I just cut as pasted it from Google docs where I wrote this post. I have no idea how that is working!

One thought on “Exceptionally fast”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s