Ver Mensaje Individual
  #7 (permalink)  
Antiguo 29/12/2005, 09:30
Avatar de Jose_minglein2
Jose_minglein2
 
Fecha de Ingreso: noviembre-2004
Mensajes: 2.344
Antigüedad: 20 años, 3 meses
Puntos: 8
http://msdn.microsoft.com/library/de...etperftips.asp
Cita:
Throw Fewer Exceptions

Throwing exceptions can be very expensive, so make sure that you don't throw a lot of them. Use Perfmon to see how many exceptions your application is throwing. It may surprise you to find that certain areas of your application throw more exceptions than you expected. For better granularity, you can also check the exception number programmatically by using Performance Counters.

Finding and designing away exception-heavy code can result in a decent perf win. Bear in mind that this has nothing to do with try/catch blocks: you only incur the cost when the actual exception is thrown. You can use as many try/catch blocks as you want. Using exceptions gratuitously is where you lose performance. For example, you should stay away from things like using exceptions for control flow.

Here's a simple example of how expensive exceptions can be: we'll simply run through a For loop, generating thousands or exceptions and then terminating. Try commenting out the throw statement to see the difference in speed: those exceptions result in tremendous overhead.