Raised This Month: $ Target: $400
 0% 

switch or if Faster?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
0920357689
Senior Member
Join Date: Apr 2008
Old 01-14-2011 , 17:23   switch or if Faster?
Reply With Quote #1

Code:
switch(bool:variable)
 {
  case false:
  {
  }
  case true:
  {
  }
 }
Code:
if(bool:variable)
   {
   }else{
   }
Which one faster?
0920357689 is offline
Owner123
Member
Join Date: Jun 2010
Old 01-14-2011 , 17:29   Re: switch or if Faster?
Reply With Quote #2

In this case, this dont make any difference.
__________________
Sorry for my bad english !
Owner123 is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 01-14-2011 , 17:31   Re: switch or if Faster?
Reply With Quote #3

if "if" have more else
shitch will faster??

look like

Code:
 
if(variable == X)
{
}
else if(variable == Y)
{
}
else if(variable == Z)
{
}
0920357689 is offline
Owner123
Member
Join Date: Jun 2010
Old 01-14-2011 , 17:43   Re: switch or if Faster?
Reply With Quote #4

In performing by CPU this looks the same.
__________________
Sorry for my bad english !
Owner123 is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 01-14-2011 , 17:47   Re: switch or if Faster?
Reply With Quote #5

Quote:
Originally Posted by Owner123 View Post
In performing by CPU this looks the same.
ok thx
0920357689 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-14-2011 , 18:13   Re: switch or if Faster?
Reply With Quote #6

Quote:
Originally Posted by Owner123 View Post
In performing by CPU this looks the same.
I believe that is wrong.


Quote:
Originally Posted by 0920357689 View Post
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.
__________________
fysiks is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 01-14-2011 , 18:17   Re: switch or if Faster?
Reply With Quote #7

Switches are usually need when there is one or more possibility for a variable. If statements are usually 2 conditions.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-15-2011 , 01:29   Re: switch or if Faster?
Reply With Quote #8

http://wiki.amxmodx.org/Optimizing_P...d_X_Scripting)
__________________
fysiks 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 02:12.


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