> > How about just <cfif Attributes.Json IS "on"></cfif> (the "IS" test
isn't
> a
> > case-sensitive test).
> > :-)
>
> I read a while back that compareNoCase is a faster way of comparing
strings
> than using IS...

Correct.  Since CompareNoCase() is a boolean expression, it supposedly
executes faster than a string expression like IS.  From what I understand,
this is true for all boolean vs. string comparisons.  I do use
CompareNoCase() over IS myself, but I have found that it's not the most
"user-friendly" code and tends to confuse the heck out of the newer codings
because you have to use a NOT modifier in order to test for a true boolean
condition.  So...

<CFIF NOT CompareNoCase(Attributes.Json, "on")>

...may be faster, but...

<CFIF Attributes.Json IS "on">

...is the more intuative approach and doesn't confuse the heck out of people
(also takes less time to type).  It all depends on how your application
needs to work I guess.  If you have a lot of load, or you're looping over
thousands of lines (see below) and need to cram every last millisecond of
performance out of CF, the CompareNoCase() may be better, but if you need
the app done yesterday, and there's the possibility of a newer coder working
on it in the future, it may be worth the slight performance drop to use the
IS comparison.

Just as a reference, I tested the two methods on my Compaq 1850r server,
which has a single PII-400 processor.

The first code sample..

<CFSET Variables.DS = "this">
<CFLOOP FROM="1" TO="5000" INDEX="key">
 <CFIF Variables.DS IS "this"> </CFIF>
</CFLOOP>

..took an average of 1265 milliseconds to complete according to the
debugging info.  The second sample..

<CFSET Variables.DS = "this">
<CFLOOP FROM="1" TO="5000" INDEX="key">
 <CFIF NOT CompareNoCase(Variables.DS, "this")> </CFIF>
</CFLOOP>

..averaged 453 milliseconds.  So, it would appear that using the boolean
operator really IS faster, and that whatever it is that the previous poster
mentioned was correct.


-Justin Scott, Staff Developer
 http://www.annex.com



PS: Sorry about the crosspost on CF-Talk.  It was a good thread on the
fusebox list and I thought it would benefit the "rookie" developers on the
list since they probably never thought about this kind of stuff.  I know I
never did until about 8 months ago <g>.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to