Friday 15 August 2014

optimization - C# Execution speed: equal (==) vs not equal (!=) -


I am trying to find some best practices for the statements, when I have to switch to something similar, That is, if other construction is required, then I usually write the condition on "not equal". The reason behind this is that usually, when there is a non-successful result, the number of instructions and their complexity is also low. Is there any difference on the comparison process? There is no difference between execution time between (==) and not equal (! =)?

Example (one but rather simple one, but holds the general idea):

  string mystring = "weekend"; If (myString! = "Weekend") {Console.WriteLine ("No Fun ...!"); } Else {// a bunch of fun stuff with relatively high complexity / can expand on many lines of several codes}   

Do I have any difference in execution time if I- Else statement?

  string myString = "weekend"; If (MyString == "Weekend") {// can be a bunch of fun stuff with relatively high complexity / extension on many lines of multiple codes} and {console}. WrightLine ("No Fun ...!"); }   

I would say that you should write that this is the most readable. Such micro-optimization is unlikely to understand any differences in your code: if you are doing a "no" operation compared to maximum if this is an important difference then the compiler will do it anyway Will also optimize, but do not really think about it either.

No comments:

Post a Comment