Posts: 1,219
Threads: 51
Joined: Jul 2012
No matter which one is faster, don't use switch in such a situation.
Anyways, you can do benchmarks by running both very often, saving the start time and comparing it to the end time.
Posts: 1,266
Threads: 6
Joined: Oct 2014
Switch and if got their own usage.
If you use if in switch place it will be slow and if you use switch in if place it will be slow.
How?
Lets say you need to check for 1 and 3000 by switch you do
PHP код:
switch(var)
{
case 1..3000:
{
}
default:
{
}
}
At this case switch used in if place and will be slow so have to use
PHP код:
if(0 < var < 3001)
{
}
So we get to this point switch is faster when switch is needed ( your above post declears switch example )
And if is faster when if is needed.
Posts: 163
Threads: 18
Joined: Nov 2008
Reputation:
0
So..
i know if usage, but sometimes i can use switch in place of if (like my example above) and both of these two have same ticktime to process, right?
Posts: 1,266
Threads: 6
Joined: Oct 2014
Quote:
Originally Posted by rolex
So..
i know if usage, but sometimes i can use switch in place of if (like my example above)
|
exactly D:
Quote:
Originally Posted by rolex
both of these two have same ticktime to process, right?
|
Didn't get what you mean : o, mind explaining?
Posts: 163
Threads: 18
Joined: Nov 2008
Reputation:
0
In my example above, switch and if have same benchmark!?
Posts: 294
Threads: 12
Joined: Sep 2015
Reputation:
0
why worry about this not real problem? did you profile to see that this was the real problem? no i bet you dont! other code is a problem not this so do not worry
Posts: 163
Threads: 18
Joined: Nov 2008
Reputation:
0
This is not a "problem" for me, and i never said that.
It's just a question, and aswered!
Thank you'all.