It was my understanding that cfparam under CF5 was just shorthand notation for "if not isDefined then set." It probably behaves similarly under CFMX. My timing shows that writing "if not stuctKeyExists then set" is faster than using cfparam.
Each of the below code segments was looped over 20,000 times and 40 runs were averaged together. I was surprised how much faster CFMX was than CF5 (they are both running on my PC). Note that CF seems to have a timing accuracy of + or - 10ms, and that future runs had the "structKeyExists cfscript syntax" and "structKeyExists tag syntax" often switch speed positions with each other. StructKeyExists under CFMX was always faster than isDefined, and under CF5 it was always slower than isDefined.
CFMX 6.1 results
structKeyExists: 98 ms
isDefined: 119 ms
if not structKeyExists cfscript syntax: 137 ms
if not structKeyExists tag syntax: 142 ms
<cfparam>: 273 ms
CF5 results
structKeyExists: 732 ms
isDefined: 684 ms
if not structKeyExists cfscript syntax: 805 ms
if not structKeyExists tag syntax: 832 ms
<cfparam>: 7646 ms
Tests:
isDefined:
<cfset x = isDefined("form.field#i#")>
structKeyExists:
<cfset x = structKeyExists(form,"field#i#")>
if not structKeyExists cfscript syntax:
<cfscript>if(NOT structKeyExists(form,'field#i#')) form.field=123;</cfscript>
if not structKeyExists tag syntax:
<cfif NOT structKeyExists(form,'field#i#')><cfset form.field=123></cfif>
<cfparam>:
<cfparam name="form.field#i#" default="123">
Enjoy,
Mike Chabot
PS: Does anyone know why my E-mail to the list using Eudora never seem to make it, even though they arrive to my bcc: address just fine. I have to use the online form in order to post. The e-mail address I am sending from is the same address I am using to subscribe to the list.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

