Code Style
Hello Alliedmods,
My Question: What is more efficient? Method 1: PHP Code:
PHP Code:
|
Re: Code Style
Not really sure it makes that much of a difference. They are both only calling one check. Not sure :)
|
Re: Code Style
Method 2 will allow more code in the function if headshot is true, method 1 will not. However, if that code was alone in the function, it would not matter. Method 2 is better over all.
|
Re: Code Style
Firippu you are wrong about method 2 being better.
It makes no difference in efficiency, but you can use it to make your code easier to read. Instead of this: PHP Code:
PHP Code:
|
Re: Code Style
Like I said, if the code was alone(like the example mottzi posted), it would not matter which one you choose. However, if you wanted to execute more code after it, regardless if headshot is true or false, you would have to use method 2 or else it wouldn't reach it, unless headshot was false. Method 2 is more flexible, not more efficient.
|
Re: Code Style
This way its faster:
Code:
|
Re: Code Style
Can you explain this "magic"
Code:
? |
Re: Code Style
Quote:
and ":" is how the else in a if too. |
Re: Code Style
owh, thanks.
|
Re: Code Style
Quote:
Method #1 would use several return statements. When these are put into the assembly code, method #1 has many jumps which could be avoided by using method #2. I don't remember where this was discussed or who said it, though. |
| All times are GMT -4. The time now is 10:22. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.