On 4/26/02, Paul Giesenhagen penned: >cfswitch is much faster ... but both are usable in different situations ... >look through the archives, others have done tests and outputed their >variances.... > >I am assuming it is faster because it doesn't have to evaluate an expression >and just has to evaluate a value.
I think CF somehow parses the entire cfswitch statement at once, where with cfif/elseif, it checks the first, then the next, then the next, and so on. But, I wouldn't call it MUCH faster, in fact based on my testing it's slower in most situations. Here are the results of some testing I've done using a LONG cfif or cfswitch (evaluate 200 conditions). <cfswitch expression="#test#"> <cfcase value="1"><CFOUTPUT>#test#</CFOUTPUT></cfcase> <cfcase value="2"><CFOUTPUT>#test#</CFOUTPUT></cfcase> snipped 3 through 199 <cfcase value="200"><CFOUTPUT>#test#</CFOUTPUT></cfcase> </cfswitch> and <cfif test is 1><CFOUTPUT>#test#</CFOUTPUT> <cfelseif test is 2><CFOUTPUT>#test#</CFOUTPUT> snipped 3 through 199 <cfelseif test is 200><CFOUTPUT>#test#</CFOUTPUT> </cfif> Setting test to "199": switch: first run = 393 ms, reloads = 4 to 5 ms if: first run = 372 ms, reloads = 16 to 18 ms Setting test to "10": switch: first run = 394 ms, reloads = 4 to 5 ms if: first run = 341 ms, reloads = 4 to 5 ms Reducing my switch or if to 10 lines and setting test to "10", I get this: switch: first run = 65 ms, reloads = 3 to 5 ms if: first run = 52 ms, reloads = 4 to 5 ms So, in summary, at least in my testing (4.5 by the way)... CFIF runs faster on the first run, the sooner the condition returns true the faster, as compared to CFSWITCH. CFIF processing times seem to be affected by the number of conditions and where it returns true. It stops processing as soon as it hits a true condition. CFSWITCH is faster on subsequent runs, the later the condition returns true the faster, as compared to CFIF. CFSWITCH always seems to take about as long no matter how many conditions are being evaluated and where the condition returns true. When evaluating a more reasonable number of conditions, such as 10 or 20, the difference is so negligible it's not worth thinking about. -- Bud Schneehagen - Tropical Web Creations _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ ColdFusion Solutions / eCommerce Development [EMAIL PROTECTED] http://www.twcreations.com/ 954.721.3452 ______________________________________________________________________ Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

