473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

if else VS switch

Don
Hi,

The behavior between if else and switch is not different in PHP.
However is there difference for the performance (I know in C it's
different) while interpreting the script?

Thanks in advance

Don
May 1 '06 #1
3 2680
Don <NO*********@free.fr> wrote in news:44561ee5$0$14027
$6*******@news.free.fr:
Hi,

The behavior between if else and switch is not different in PHP.
However is there difference for the performance (I know in C it's
different) while interpreting the script?

Thanks in advance


if i recall correctly, one of the bugfixes/improvements to the
latest/greatest PHP version was improving the speed of switch statements...
so I assume they are as fast as if/else at least right now...

obviously the real benefit of using 'switch' is that its great for going
through many possible conditions, and results in far more readable code.
May 1 '06 #2
Don wrote:
Hi,

The behavior between if else and switch is not different in PHP.
However is there difference for the performance (I know in C it's
different) while interpreting the script?

Thanks in advance

Don

Why don't you test it ? using microtime() this should be a piece of cake.

Which one should be faster in C according to your data?
Sh.

--
Sigh. I like to think it's just the Linux people who want to be on
the "leading edge" so bad they walk right off the precipice.
(Craig E. Groeschel)
May 2 '06 #3
Don wrote:
Hi,

The behavior between if else and switch is not different in PHP.
However is there difference for the performance (I know in C it's
different) while interpreting the script?


IIRC, switch is based on look up tables and might be faster.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

May 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gurikar | last post by:
Whats the difference b/w swicth case and if else if. Iam finding both are same when you are using in application. Only difference if else if more flexible to use with all data types. But some...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
11
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at...
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
13
by: Michael Griebe | last post by:
Simple question. I am optimizing some C++ code and I'd like to know which is faster (or if there is any difference at all) between using a switch statement or nested else-ifs. I'm partial to...
5
by: sam_cit | last post by:
Hi Everyone, I read somewhere that there are some compile time operations behind switch-case, which is why it can work for cases which evaluates to an integer or character and not strings and...
3
by: shror | last post by:
I was testing to post a form and echo message according to the submitted box using else if and then mail() the box result to myself just for testing the procedure but i got some problems: 1# the...
17
by: JRough | last post by:
I'm trying to get error proof code. I have this code which seems to work but now I look at it I think it should be elseif not else and I wonder why it works. It is in the block:...
7
by: Peter | last post by:
Hi I have a property (item.Id) which contains a Guid. Based on the value of this Guid I have to execute one of several different tasks. The tasks are really all variations on the theme "obtain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.