I just managed to get APD installed, so I'd like to know...
What is your view on profiling? Do you do it often? How do you go about profiling an application? What is your preferred profiler for PHP?
Profiling
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Profiling
I wrote an article on profiling in general a few years back...Ambush Commander wrote:I just managed to get APD installed, so I'd like to know...
What is your view on profiling? Do you do it often? How do you go about profiling an application? What is your preferred profiler for PHP?
Not to give my article a plug, but WTH
http://www.codeproject.com/cpp/profiler.asp
My rating appears to have taken a dive since I last looked
Anyways, IMHO, I outline a general idea as to what profiling is and where you can apply techniques to languages like PHP - which may not automatically apply optimizations. Although I imagine the Zend engine does much of what VC++ compiler does???
My opinion on profiling...in PHP...I follow the simple rule: Keep any loops tight as possible
I also:
1) Always use single quotes - no variable interpolation
2) Use non-regex functions when possible str_replace as opposed to ereg_replace, etc...
3) Optimize SQL queries
4) Don't use mail() in a loop
5) Keep whitespace to a minimum - without affecting readability of course or comments
6) Ahhh...I can't think of anymore right now
What do I use for profiling? Well if memory serves me correctly...PHP's microtime() don't do a very good job...
http://ca3.php.net/manual/en/function.microtime.php
I've tried that code in the sample and everytime I ran it on loops using very high iterations I would always get such crazy results I basically gave up on the microtime being that accurate - so basically I Gave up on hardcore profiling
I imagine there are apps which hook into the actual PHP code and using native C code allow you to profile entire functions much more accurately than PHP's microtime...but again IMHO...
Hardcore profiling isn't really worth it anymore these days...
It served it's purpose back in the day when clock cycles were precious commodity...but these days...
If you writing an application large enough, with a massive user base, it's likely more cost effective to just perform basic optimizations and instead opt for upgrading hardware, etc...then it is to dig through code finding every little cranny which you can optimize.
So, I say...profiling and optimizing beyond what I suggest above is not needed, hardcore profiling is best left for those academic types who need something to research
Just my two cents
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Re: Profiling
I've used Apache AB and xDebug. Also use a perl script to profile shared servers. (Thought about using JMeter instead but I trust my perl script not to whack the server.) I don't use AB and xDebug unless I have a performance problem I can't figure out. Usually I don't have anything big enough to worry about profiling. The perl script I use with every new customer on a shared server and after every server upgrade.Ambush Commander wrote:I just managed to get APD installed, so I'd like to know...
What is your view on profiling? Do you do it often? How do you go about profiling an application? What is your preferred profiler for PHP?
I do use the microtime function, I find it useful for big thing like the entire page. Certainly not as accurate as xDebug but good enough for somethings.Hockey wrote:Well if memory serves me correctly...PHP's microtime() don't do a very good job...
Loops, regular expression and database queries are usually areas to be careful. I don't think it matters weather you use single or double quotes however using the output buffer gives you a 40K chuck of memory to use for string concatenation. I strip whitespace and comments on upload not because of PHP performance but the hard drive performance. I get a 50% plus reduction in the size of my PHP files.Hockey wrote:My opinion on profiling...in PHP...I follow the simple rule: Keep any loops tight as possible
I also:
1) Always use single quotes - no variable interpolation
2) Use non-regex functions when possible str_replace as opposed to ereg_replace, etc...
3) Optimize SQL queries
4) Don't use mail() in a loop
5) Keep whitespace to a minimum - without affecting readability of course or commentsI use an editor which automatically clips whitespace from EOL.
6) Ahhh...I can't think of anymore right now
It's still used today on really big projects like at Yahoo where hardware is cheap and really small project like mine where hardware ain't cheap or even an option.It served it's purpose back in the day when clock cycles were precious commodity...but these days...
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Let me answer my own questions now...
I think profiling probably is better than random guessing what the worst parts of the code are, haven't been to the point where I've never been able to figure out the bottleneck, so I don't have any real experience with a profiler. Sorry, microtime() does not count as "profiling", so I currently have only used APD and XDebug.
2. Definitely, but don't go out on a limb adding extra complexity. In some surprising cases, regexps perform better than any algorithms you can make, so use it.
3. Once again, this can add code complexity, so be careful.
4. Yum.
5. Okay, I can't agree with that. I don't think whitespace has any effect except on filesizes.
I think profiling probably is better than random guessing what the worst parts of the code are, haven't been to the point where I've never been able to figure out the bottleneck, so I don't have any real experience with a profiler. Sorry, microtime() does not count as "profiling", so I currently have only used APD and XDebug.
Agreed. Very very important. But profiling can help you find those little inefficient buggers...Hockey wrote:Keep any loops tight as possible
1. I really don't think the difference is that great, so much that it would be a rounding error compared to SQL. Interpolation makes code easier to read.Hockey wrote:(the list)
2. Definitely, but don't go out on a limb adding extra complexity. In some surprising cases, regexps perform better than any algorithms you can make, so use it.
3. Once again, this can add code complexity, so be careful.
4. Yum.
5. Okay, I can't agree with that. I don't think whitespace has any effect except on filesizes.
Once again, this isn't "profiling", it will only catch spots that you actually take a look at.Hockey wrote:What do I use for profiling? Well if memory serves me correctly...PHP's microtime() don't do a very good job...
Negative stuff right? Try microtime() + time()Hockey wrote:I've tried that code in the sample and everytime I ran it on loops using very high iterations I would always get such crazy results I basically gave up on the microtime being that accurate - so basically I Gave up on hardcore profiling
If you had the foresight to program for a distributed environment and your applications scales horizontally.Hockey wrote:If you writing an application large enough, with a massive user base, it's likely more cost effective to just perform basic optimizations and instead opt for upgrading hardware, etc...then it is to dig through code finding every little cranny which you can optimize.