Here's a rudimentary test case.
What's really interresting about this test is that, although the sum total
time required to perform 10000 ( or however many ) try-catch blocks to
accomplish roughly the same thing as the <cfswitch> statements, is about 7-8
times as long, the maximum and average times in _both_ cases are identical,
regardless of how many iterations are used. Or at least, this has been the
case in my testing...
Admittedly, this isn't real load testing, it's just a rudimentary time test,
so it should be taken with a grain of salt. It also doesn't compare the
try-catch to a <cfif> ladder, which might also be a relevant comparison.
In any event, here's the code if you'd like to see the times for yourself:
<cfparam name="url.iterations" type="numeric" default="10000">
<cfset request.times_try = ArrayNew(1)>
<cfset request.times_switch = arraynew(1)>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Try-Catch Time Test</title></head><body>
<cfloop index="iteration" from="1" to="#url.iterations#">
<cfset starttime = gettickcount()>
<cfset candrive = false>
<cfset candrink = false>
<cfset myage = RandRange(1,35)>
<cfswitch expression="#myage#">
<cfcase value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
delimiters=",">
<cfset message="this is a tyke">
</cfcase>
<cfcase value="16,17,18,19,20" delimiters=",">
<cfset candrive = true>
<cfset message="this is a teen">
</cfcase>
<cfdefaultcase>
<cfset candrink = 1>
<cfset message="this is an adult">
</cfdefaultcase>
</cfswitch>
<cfset executiontime = gettickcount() - starttime>
<cfset temp = arrayappend(request.times_switch,executiontime)>
<cfset starttime = gettickcount()>
<cfset candrive = false>
<cfset candrink = false>
<cfset myage = RandRange(1,35)>
<cftry>
<cfif myage lt 16><cfthrow type="tyke"></cfif>
<cfset candrive = true>
<cfif myage lt 21><cfthrow type="teen"></cfif>
<cfset candrink = true>
<cfset message="this is an adult">
<cfcatch type="tyke"><cfset message="this is a tyke"></cfcatch>
<cfcatch type="teen"><cfset message="this is a teen"></cfcatch>
</cftry>
<cfset executiontime = gettickcount() - starttime>
<cfset temp = arrayappend(request.times_try,executiontime)>
</cfloop>
<cfoutput>
Iterations: #arraylen(request.times_switch)# - #arraylen(request.times_try)#
<table>
<tr><td>method</td><td>min</td><td>max</td><td>avg</td><td>sum</td></tr>
<tr><td>switch</td>
<td>#ceiling(arraymin(request.times_switch))#</td>
<td>#ceiling(arraymax(request.times_switch))#</td>
<td>#ceiling(arrayavg(request.times_switch))#</td>
<td>#ceiling(arraysum(request.times_switch))#</td>
</tr>
<tr><td>try</td>
<td>#ceiling(arraymin(request.times_try))#</td>
<td>#ceiling(arraymax(request.times_try))#</td>
<td>#ceiling(arrayavg(request.times_try))#</td>
<td>#ceiling(arraysum(request.times_try))#</td>
</tr>
</table>
</cfoutput>
</body>
Isaac Dealey
Certified Advanced ColdFusion 5 Developer
new epoch
www.turnkey.to
954-776-0046
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm