AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   switch or if Faster? (https://forums.alliedmods.net/showthread.php?t=147835)

0920357689 01-14-2011 17:23

switch or if Faster?
 
Code:

switch(bool:variable)
 {
  case false:
  {
  }
  case true:
  {
  }
 }

Code:

if(bool:variable)
  {
  }else{
  }

Which one faster?

Owner123 01-14-2011 17:29

Re: switch or if Faster?
 
In this case, this dont make any difference.

0920357689 01-14-2011 17:31

Re: switch or if Faster?
 
if "if" have more else
shitch will faster??

look like

Code:


if(variable == X)
{
}
else if(variable == Y)
{
}
else if(variable == Z)
{
}


Owner123 01-14-2011 17:43

Re: switch or if Faster?
 
In performing by CPU this looks the same.

0920357689 01-14-2011 17:47

Re: switch or if Faster?
 
Quote:

Originally Posted by Owner123 (Post 1393676)
In performing by CPU this looks the same.

ok thx

fysiks 01-14-2011 18:13

Re: switch or if Faster?
 
Quote:

Originally Posted by Owner123 (Post 1393676)
In performing by CPU this looks the same.

I believe that is wrong.


Quote:

Originally Posted by 0920357689 (Post 1393668)
if "if" have more else
shitch will faster??

look like

Code:


if(variable == X)
{
}
else if(variable == Y)
{
}
else if(variable == Z)
{
}


A switch should be used here. It is more efficient.

GXLZPGX 01-14-2011 18:17

Re: switch or if Faster?
 
Switches are usually need when there is one or more possibility for a variable. If statements are usually 2 conditions.

fysiks 01-15-2011 01:29

Re: switch or if Faster?
 
http://wiki.amxmodx.org/Optimizing_P...d_X_Scripting)


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

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