Raised This Month: $ Target: $400
 0% 

Is here any diff in these lines?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-04-2010 , 06:23   Is here any diff in these lines?
Reply With Quote #1

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?

Last edited by 9evill; 08-04-2010 at 06:25.
9evill is offline
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 08-04-2010 , 06:30   Re: Is here any diff in these lines?
Reply With Quote #2

There are no difference but :

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



if (!is_user_alive(id) || zp_get_user_zombie[id]) return PLUGIN_CONTINUE
__________________
You can do anything you set your mind to, man.

Devil259 is offline
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 08-04-2010 , 06:33   Re: Is here any diff in these lines?
Reply With Quote #3

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

__________________

Last edited by vato loco [GE-S]; 08-04-2010 at 06:36.
vato loco [GE-S] is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-04-2010 , 06:45   Re: Is here any diff in these lines?
Reply With Quote #4

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?
9evill is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 08-04-2010 , 07:12   Re: Is here any diff in these lines?
Reply With Quote #5

Quote:
Originally Posted by 9evill View Post
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.

Last edited by Seta00; 08-04-2010 at 08:54.
Seta00 is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-04-2010 , 08:21   Re: Is here any diff in these lines?
Reply With Quote #6

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?
9evill is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 08-04-2010 , 08:51   Re: Is here any diff in these lines?
Reply With Quote #7

Quote:
Originally Posted by 9evill View Post
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.
Seta00 is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 08-04-2010 , 09:34   Re: Is here any diff in these lines?
Reply With Quote #8

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
9evill is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 08-04-2010 , 15:23   Re: Is here any diff in these lines?
Reply With Quote #9

Then I suggest you to go there, save 150k calls and tell me if you see the difference.
Seta00 is offline
9evill
Senior Member
Join Date: Apr 2007
Location: Lithuania
Old 10-14-2010 , 10:32   Re: Is here any diff in these lines?
Reply With Quote #10

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?
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.
9evill is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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