Monday, September 28, 2009

The Performance Cost Of Throwing Exceptions (or Custom Exceptions) In ColdFusion

A couple months back, I read Ben Nadel's blog on The Performance Cost Of Throwing Exceptions In ColdFusion.  It made me curious how my custom validation exception would perform.  Using Ben's code, I ran a base test on my computer to have an apples to apples comparison.


The ColdFusion cfthrow Test

Throw Exception: false 
  • Results: 63 
  • Results: 63 
  • Results: 47
  • Results: 62
  • Results: 62
Throw Exception: true
  • Results: 890 
  • Results: 718
  • Results: 672
  • Results: 672
  • Results: 1,219
Custom Exception for Validation
Throw Exception: false 
  • Results: 62
  • Results: 62 
  • Results: 63
  • Results: 62
  • Results: 63
Throw Exception: true
  • Results: 422
  • Results: 438
  • Results: 406
  • Results: 422
  • Results: 391
 I'M BAFFLED! 

I expected my custom exception to run slower than coldFusion's exception. My java code just inherits RuntimeException, and then I cfthrow object="javaObject".  I'm curious what cfthrow message="me" does that it is twice as slow.