AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is here any diff in these lines? (https://forums.alliedmods.net/showthread.php?t=134394)

9evill 08-04-2010 06:23

Is here any diff in these lines?
 
Hello. i want to know is here any difference if i check everything in one line or in two?
here is example
Code:

public FW_PlayerPreThink(id)
{
    if (!is_user_alive(id)) return PLUGIN_CONTINUE
    if (zp_get_user_zombie(id)) return PLUGIN_CONTINUE
...

Code:

public FW_PlayerPreThink(id)
{
    if (!is_user_alive(id) || !zp_get_user_zombie[id]) return PLUGIN_CONTINUE
...

if everything are in one line is they checked allways, or only if first checks fails?
which one of above examples is better by performance side? Or they both are same?

Devil259 08-04-2010 06:30

Re: Is here any diff in these lines?
 
There are no difference but :

if (!is_user_alive(id) || !zp_get_user_zombie[id]) return PLUGIN_CONTINUE

:arrow:

if (!is_user_alive(id) || zp_get_user_zombie[id]) return PLUGIN_CONTINUE

vato loco [GE-S] 08-04-2010 06:33

Re: Is here any diff in these lines?
 
i would use it like this
PHP Code:

public FW_PlayerPreThink(id)
{
    
// if player not alive or not zombie plugin returns continue
    
if (!is_user_alive(id) || !zp_get_user_zombie[id]) return PLUGIN_CONTINUE


PHP Code:

public FW_PlayerPreThink(id)
{
    
// if player not alive or zombie plugin returns continue
    
if (!is_user_alive(id) || zp_get_user_zombie[id]) return PLUGIN_CONTINUE



9evill 08-04-2010 06:45

Re: Is here any diff in these lines?
 
So in both examples plugin will use same ammount of calls?

my thoughts about these in case of dead user:
in first example plugin check if user alive and if not returns - one call (zombie check not called)
in second example plugin check if user alive or is not zombie - two calls. Or plugin returns just after if_user_alive check?

Seta00 08-04-2010 07:12

Re: Is here any diff in these lines?
 
Quote:

Originally Posted by 9evill (Post 1261325)
Or plugin returns just after if_user_alive check?

It doesn't. Using two ifs is faster but pointless, as the speed difference will be insignificant.

On the other side, in this code:
Code:
if (!is_user_alive(id) && !zp_get_user_zombie(id))
If the first check (is_user_alive) fails, the other one never gets executed.

9evill 08-04-2010 08:21

Re: Is here any diff in these lines?
 
hmm, if FW_PlayerPreThink called 100 per second, and server have 32 players, so then i save 1 call in code, i save 3200 calls per second? Or iam wrong? :)

Seta00 08-04-2010 08:51

Re: Is here any diff in these lines?
 
Quote:

Originally Posted by 9evill (Post 1261365)
hmm, if FW_PlayerPreThink called 100 per second, and server have 32 players, so then i save 1 call in code, i save 3200 calls per second? Or iam wrong? :)

Still insignificant.

9evill 08-04-2010 09:34

Re: Is here any diff in these lines?
 
Yea, but that was just an example, if i save 10 calls, whats already 32k saved calls per second. If i review all plugins and save say 50 calls, whats will be 160k :)

Seta00 08-04-2010 15:23

Re: Is here any diff in these lines?
 
Then I suggest you to go there, save 150k calls and tell me if you see the difference.

9evill 10-14-2010 10:32

Re: Is here any diff in these lines?
 
So, after big and hard work of my plugins and optimizations here is a result:

[IMG]http://img715.**************/img715/5404/graphimage.png[/IMG]

Still you think it is insignificant? :nono:
Ofcourse, it is not a result only of those seperated "if" checks, but if you optimize a everything you can, you can reach a really good results.


All times are GMT -4. The time now is 00:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.