Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure PHP script execution in CPU cycles?

Tags:

php

How can I measure my PHP script execution in CPU cycles? I do not need execution time, because if script connects to db or to external API , its waiting and do not consume CPU resources.

EDIT: PHP<5.3, Windows

like image 723
codez Avatar asked Jun 29 '10 11:06

codez


Video Answer


2 Answers

Have a look at the getrusage() function. It might provide you with something useful

like image 153
Mark Baker Avatar answered Sep 22 '22 18:09

Mark Baker


Try using a profiler. ( http://xdebug.org/docs/profiler )

Measuring code cycles may vary because the zend engine may or may not optimized the opcodes, the way the zend engine was compiled may lead to it doing some operations faster, etc.

Also, the time it takes to connect to the DB may be "handled" by doing some mock classes (http://en.wikipedia.org/wiki/Mock_object), but in a real application, the time it takes to connect to the DB is important, because the user perceives the whole webpage as being slow, not the SQL server being slow:)

like image 22
Quamis Avatar answered Sep 22 '22 18:09

Quamis