| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Soon to be RICHdoggie! | Quicker PHP scripts? Hi. I want to find out if these are quicker, slower or if there is no difference... Would changing this: PHP Code: PHP Code: and would this: PHP Code: PHP Code: Tom |
| |
| | #6 (permalink) |
![]() | In both sets above, neiter would make any difference, and if it did, it would be insignificant as mikesherov suggested. But if you want to test it yourself, you can use the following code to test the pages loading time: Put this code above the code you want to time: PHP Code: PHP Code: Rhett.
__________________ <?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?> |
| |
| | #8 (permalink) | |
| Senior Member | Quote:
__________________ Donate to the NP Emergency Fund Today! | |
| |
| | #9 (permalink) |
| Domains my Dominion | You should try with some benchmarking but I don't think it makes a difference these days because the PHP & ASP parsers are more powerful than they were in the past. Anyway I prefer not to mix PHP with HTML because the code is really messy and hard to read after... not worth it
__________________ Buy now - MassDeveloper.com $500 |
| |
| | #10 (permalink) | |
| Senior Member | Quote:
For a small site you are right it does not make a huge difference but for sites that server hundreds of thousands of users then it can make a huge difference.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #11 (permalink) | |
| NamePros Regular | Quote:
This makes code unreadable and hard to maintain. This is especially so for big sites, so i disagree with filth@flexiwebhost. If you really think that this will have speed improvements, do keep an original copy before squeezing them into 1 line, so that maintenance in future is easier. | |
| |
| | #13 (permalink) | |
![]() | Quote:
You can't really optmize the php statements you have, usually there can be a lot of optimization when it comes to mysql and things, but not basic statements, they're as fast as they can be
__________________ <?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?> | |
| |
| | #14 (permalink) |
| NamePros Member | Well, in principle, you can right more efficient code... but something like 1 assignment operation vs. 6 assignment operations is insignificant... a little trick I like to use to increase my code efficiency: When generating <SELECT> tags: using str_replace vs. if,then,else to select a default value... as follows: instead of: PHP Code: PHP Code: It's all about thinking as follows: What the best code to do rounding (in this example, I consider rounding to the nearest integer)? one approach (the long way): PHP Code: PHP Code: |
| |
| | #15 (permalink) | |
| Senior Member | Quote:
My post was a direct response of what Dan Friedman which was that no function sped up a script enough to worry about trying.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #17 (permalink) | |
| Senior Member | Quote:
Look around the internet regarding optimizing php scripts. Granted alot of sites it wouldn't make a huge difference with but if a site takes off then you would be starting on the wrong foot.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #18 (permalink) | |
| Senior Member | Quote:
http://blogs.hackerscenter.com/dcrab/?p=9
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #20 (permalink) |
| Buy my domains. | I just did a test between str_replace, ereg_replace, eregi_replace, and preg_replace. I replaced all vowels with nothing in the sentence "Which function is faster? str_replace or eregi_replace" 1000 times. str_replace: 0.0077230930328369 seconds preg_replace: 0.0092120170593262 seconds eregi_replace: 0.011637926101685 seconds ereg_replace: 0.01211404800415 seconds |
| |
| | #21 (permalink) |
| Senior Member | Dan you missed the point of the post, Yes he showed the obvious slow functions to prove a point. Languages such as php have many different ways of achieving the same end result and before deciding which to choose you should know which has the most processing power and execution time. For example say you have a mailling list of which 5000 people are subscribed. To send a message to each 1 using the mail() function requires php to open a connection 5000 times (it cloese the connection after each email has been sent). This of course courses overheads server wise as well as an increase of execution time. The same thing can be achieved by making a connection to an smtp server and sending the 5000 emails with only 1 connection, this will save processing power and execution time as it does not have to open and close a connection EVERY time a new message is being sent. Regardless of this the majority of people use the mail() function as 1) they know it is going to work and 2) they have no idea of the possible server overheads caused by it. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |