Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While loop quickest method

Which is more quickly evaluated? I'm using java syntax, but any programming language would apply to the question.

while (1==1) {

}

while (true) {

}

I tried testing this with a large loop. The results varied far too much to give me a solid answer.


1 Answers

What you are trying to do is a "micro optimisation". It's not worth it. Any decent compiler will produce identical code, since 1 == 1 is obviously the same as true. Even if it was different code, that little bit of change will not make any measurable difference.

like image 148
gnasher729 Avatar answered May 22 '26 07:05

gnasher729



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!