TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

40 Tips for optimizing your php Code

13 pointsby raindollover 17 years ago

3 comments

someover 17 years ago
&#62; 1. If a method can be static, declare it static. Speed improvement is by a factor of 4.<p>Wow!<p><pre><code> function Prime1() { ...calc one million prime numbers...} static function Prime2() { ...calc one million prime numbers...} </code></pre> Prime2() will calculate the prime numbers 4 times faster then Prime1()? Cool.
jbyersover 17 years ago
These range from sensible to utterly useless [1,2,3].<p>I'd say forget all of this and focus on being a productive developer, building something people want, and ruthlessly avoiding premature optimization. When your application is slow, measure it to find out why, then fix it, and repeat.<p>1. Let's take #2, "echo is faster than print" - Seriously, is this what we should be worrying about? I can't detect a difference in PHP 5.2.4 across 100,000 echos/prints, so it must not be very big.<p>2. ++i vs i++ to squeeze out 1 fewer opcode?<p>3. Using isset($foo{5}) vs a strlen check? I pity the next programmer who has to read and understand the purpose of this code.
someover 17 years ago
&#62; Set the maxvalue for your for-loops before and not in the loop.<p>What does this mean?
评论 #68057 未加载