The difference between cfif is not ... EQ and cfif ... NEQ?

Is there any difference (e.g., in terms of performance) between

<cfif not x EQ y>

and

<cfif x NEQ y> ?

+4
source share
5 answers

If at all there is any difference, I would doubt that you would notice it if you do not run it many, many, many times, or if x and y really do not work so intensively with the processor. I have never seen this interfere as a possible performance issue with Coldfusion with MX 7.

I would recommend using the format that is most readable to you. Adding errors to the code, making them difficult to read, will have a greater impact than differences in performance between the two formats.

Personally, I would prefer to see the NEQ version, as it reads better and is more common in CF.

 <cfif x NEQ y> 

It says in my head: β€œIf x is not equal to y ...” Whereas ....

 <cfif NOT x EQ y> 

reads "if not x equal to y ..." does not make sense in English.

+11
source

If you are really concerned about performance in these cases, you can use Compare or CompareNoCase, supposedly better performance than EQ.

https://web.archive.org/web/20090212085046/http://livedocs.adobe.com/wtg/public/coding_standards/performance.html

But keep in mind that these recommendations were taken from 5 years ago, and there is no more evidence than on this page that this is true.

+2
source

It really depends: on the version of ColdFusion and the data types used. In some cases, it is preferable to use specific comparison operators when you know that you are comparing these specific data types.

The ColdFusion Developers Journal, published a few years ago, had an article analyzing the performance of various operators in these scenarios (some of the features that Terry pointed to were also used). If I remember correctly, I was on CF 6 or 6.1 and showed quite significant differences in performance. But keep in mind that they tested this, wrapping up the operator’s use with a huge number of iterations, in order to get some measurable numbers first.

+1
source

As Sorensen noted, there are practically no differences in performance. Logically discussing this problem, we can identify several small things. In one case, you ask the comparator to check for equality, then you deny the results. Otherwise, ask the comparator to check the inequality. Logically, just making inequality is less of a step. However, our good friend, the hotspot compiler can change, which for us in the background makes both statements the same.

0
source

The NOT operator is a Boolean operator, and neq is a Boolean comparator. not x eq y logically equivalent to x neq y and reads better. BUT, when it becomes more complex not (x eq y or a eq b) , it may be easier to understand based on context than x neq y and a neq b , not to mention when you start getting into logical comparators ( not (x eq y or a gt b) )

0
source

Source: https://habr.com/ru/post/1301447/


All Articles