javascript - Efficient way to compare to zero -


Condition: When there is a circle, where there are some numeric variables (i.e. moreThanZero ) a zero (Usually more than ...) many cycles, more than a million say, what is the most effective / fast way to compare:

  If (MoreThanZero) { ...} If (moreThanZero> 0) {...} If (moreahairro! = 0) {...} If (more sharps! == 0) {...}   

Thanks Toraezboobo

  if (0! == moreThanZero) {...}   

Or other options?

You are probably optimizing the micro and the cost of a comparison against zero in any major program There is no possibility to see the big difference. However, for the sake of science ...

The most common optimization (for loop optimization, writing variables etc.) and to call the blackhole (ISH) function, the benchmark written by @EbrrahmedM Instead of tweaking, I might see an important difference:

How they work due to the results:

! N At least testing the specific operation at least, this (in some fashion) must treat the variable as a boolean. Some optimizations can be done and some compilers may be smart enough to use a little or no numerical comparison, but a lot of work is allowed in the language.

=== and ! == There are obviously no rape types, so they are likely to be reliably fast, with the warning that both operands should be of the same type or they are not equal. For numbers, this is likely to be an integer comparison, which should be placed below the cmp command.

& gt; May, and possibly, optimize the benefits of modern browsers, when both operands are considered numeric and especially integral. Stable, especially compared to 0, is an ideal case: a assembly instruction that compares to 0.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -