Is there performance impact of GOTO statement in c# code, instead of using loop or multiple separate user defined functions.
I am not sure but memory jump may occur with GOTO statement and can impact performance.
Is there performance impact of GOTO statement in c# code, instead of using loop or multiple separate user defined functions.
I am not sure but memory jump may occur with GOTO statement and can impact performance.
Copyright © 2021 Jogjafile Inc.
No, it doesn't.
It's hard to answer "does it impact peformance" without knowing what the alternative is but I'll make up a sample:
Compiling this with C# in release mode (using sharplab.io default 2.9.0) yields the following IL (i.e. bytecode for you Java folk):
The switch form has 3
beqand 1br.sand the goto form has 2beqand 2br.s, other than that they are identical. The cost ofbr.sis presumably less than or equal to the cost ofbeqso the cost of the goto approach is not greater than the cost of the switch approach.Finally, using goto is a bad idea. If you want to argue about that fact please do so on a different question like this one: What is wrong with using goto?