Difference between cfif not...EQ and cfif...NEQ?
Solution 1
If there is any difference at all, I'd doubt you'd notice it unless you are running this many, many, many times or unless x and y are really processor intensive somehow. I've never seen this flagged as a possible performance issue with Coldfusion since MX 7.
I would recommend using the format that is the most readable to you. Adding bugs to your code by making it hard to read will be more of an impact than the performance differences of these two formats.
Personally, I'd prefer to see the NEQ version as it reads better and is more common in CF.
<cfif x NEQ y>
In my head reads, "If x not equal to y..." Whereas....
<cfif NOT x EQ y>
reads "if not x equal to y..." doesn't make sense in English.
Solution 2
If you're really concerned about performance in these cases, you can use Compare or CompareNoCase are supposedly higher performing that EQ.
But keep in mind those recommendations are from 5 years ago, and there is no more proof then this page that it is true.
Solution 3
It really depends: on ColdFusion version and data types being used. In some cases it's preferable to use particular comparison operators when you know that you're comparing those specific data types.
There was an article in the long gone ColdFusion Developers Journal a few years ago measuring the performance of the various operators in exactly those scenarios (also using some of the functions Terry pointed to). If I remember correctly that was on CF 6 or 6.1 and showed quite significant performance differences. But then keep in mind that they've tested that by wrapping the operator use in a huge number of iterations to get some measurable figures in the first place.
froadie
Updated on June 07, 2022Comments
-
froadie almost 2 years
Is there any difference (performance-wise, for example) between
<cfif not x EQ y>
and
<cfif x NEQ y>
?