There are several niche verticals in which goto is still commonly used as standard practice, some very smart people, and there is no prejudice against goto in these settings. I used to work for a simulation-oriented company, where all the local fortran codes had gotos, the team was super smart, and the software worked almost flawlessly.
So, we can leave the dignity of goto aside, and if the question is only to compare the loops, then we do this by profiling and / or comparing the assembly code. However, the question includes statements like printf, etc. However, you cannot discuss the optimization of loop control logic. In addition, as others have indicated, these loops will generate VERY similar machine codes.
All conditional branches are considered βtakenβ (true) in the pipeline architectures of the processors one way or another prior to the decoding phase, in addition to small loops that usually expand to be inconclusive. Thus, in accordance with the Harper point above, it is unrealistic that goto has any advantage in simple contour control (just as at the same time it does not have an advantage over each other). GOTO usually makes sense in multiple nested loops or multiple nested ifs when adding an additional condition checked by goto in EACH from nested loops or nested ifs is suboptimal.
When optimizing the look of a search in a simple cycle, using a donor is sometimes more efficient than anything else. In fact, by adding a dummy value to the end of the array, you can avoid checking two conditions (the end of the array and the found value) with only one condition (the value is found) and which preserves the internal CMP operations. I do not know if compilers do this automatically.
Josh
source share