java - If(condition) else or if(condition), is there a difference in performance when using break? -


The question is a bit unclear, according to the assembly code / performance, these are equal to two:

 < Code> Public Zero Example {to {// some statement; If break (position); // Some statements; } While (right); }  

versus:

  public zero example {do} {// some statement; If (condition) {break; } Other {// some statement; }} While (true); }   

These are equivalent and their results should be in the same bytecoke representation. That's why performance-wise, they are the same.

If , else and break are branch instructions in this case, break loop off And the program will run in a separate branch. If the condition is not fulfilled, the second branch is taken, which is the same branch taken by absolutely else .

Using the Javac compiler by using the example:

  int a = System.in.read (); Do {System.out.println ("a"); If (A & gt; 0) {break; } Else {System.out.println ("b"); }} While (true);  

This produces the following without both and and :

  getstatic java / lang / system / in ljava / Io / incoming flow; InvoVertual Java / IO / Intstream / read () I istore_1 javascript / java / system / out / java / ios / printstream; : Label 1 LDC "A" invoice Java / IO / printstream / printline (Lajwa / Lang / string;) WeiLDFL & Lt; Label 2 & gt; Goto & Lt; Label 3 & gt; GetStatic Java / Long / System / Out / Slow / EO / Printstream; : Label 2 LDC "B" invoirvertical java / oo / printstream / printline (lava / long / string;) vs goto & lt; Label 1 & gt; Return: label 3  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -