Page 1 of 1

Profiling

Posted: Sun Oct 09, 2005 3:08 pm
by Ambush Commander
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?

Re: Profiling

Posted: Sun Oct 09, 2005 11:45 pm
by alex.barylski
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 wrote an article on profiling in general a few years back...

Not to give my article a plug, but WTH 8)

http://www.codeproject.com/cpp/profiler.asp

My rating appears to have taken a dive since I last looked :lol:

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 :roll:
5) Keep whitespace to a minimum - without affecting readability of course or comments ;) I use an editor which automatically clips whitespace from EOL.
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 :)

Re: Profiling

Posted: Mon Oct 10, 2005 10:11 am
by Buddha443556
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'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.
Hockey wrote:Well if memory serves me correctly...PHP's microtime() don't do a very good job...
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: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 :roll:
5) Keep whitespace to a minimum - without affecting readability of course or comments ;) I use an editor which automatically clips whitespace from EOL.
6) Ahhh...I can't think of anymore right now
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.
It served it's purpose back in the day when clock cycles were precious commodity...but these days...
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.

Posted: Mon Oct 10, 2005 7:35 pm
by Ambush Commander
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.
Hockey wrote:Keep any loops tight as possible
Agreed. Very very important. But profiling can help you find those little inefficient buggers...
Hockey wrote:(the list)
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.
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.
Hockey wrote:What do I use for profiling? Well if memory serves me correctly...PHP's microtime() don't do a very good job...
Once again, this isn't "profiling", it will only catch spots that you actually take a look at.
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
Negative stuff right? Try microtime() + time()
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.
If you had the foresight to program for a distributed environment and your applications scales horizontally.