The benefit of "early return" or short-circuit evaluation is that you can skip the evaluation of an entire statement or expression. The skipped portion is performance gain.
Your benchmark isn't setup to show this though and a general comparison is not really possible. To see the benefit of this, you need to look at algorithms that have expensive computations where short-circuit evaluation can save a noticeable amount of space/time.
Imagine a path-finding algorithm, a chess AI, or other kind of solver where millions of computations are being made. In many cases, short-circuit evaluation can be leveraged to trim many possibilities or duplicates in the solution space. Simple algorithms can benefit too, like every and some. A simple if/else if/else doesn't allow one to form any meaningful opinion about the topic.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The benefit of "early return" or short-circuit evaluation is that you can skip the evaluation of an entire statement or expression. The skipped portion is performance gain.
Your benchmark isn't setup to show this though and a general comparison is not really possible. To see the benefit of this, you need to look at algorithms that have expensive computations where short-circuit evaluation can save a noticeable amount of space/time.
Imagine a path-finding algorithm, a chess AI, or other kind of solver where millions of computations are being made. In many cases, short-circuit evaluation can be leveraged to trim many possibilities or duplicates in the solution space. Simple algorithms can benefit too, like every and some. A simple
if
/else if
/else
doesn't allow one to form any meaningful opinion about the topic.