|
|
|
|
![]() ![]() |
Jul 5 2006, 01:47 PM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 933 Joined: 24-August 04 Member No.: 892 |
As my knowledge of PHP increases, I have learned more, in this version, I use a class.
V1: http://www.trap17.com/forums/page-loading-time-t4782.html CODE <?php
class microtimer { // Starts, Ends and Displays Page Creation Time function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function s() { $this->st = $this->getmicrotime(); } function e() { $this->et = $this->getmicrotime(); echo round(($this->et - $this->st), 6); } } $tm = new microtimer; //A class is a collective function set. Stick that in a file that's included or in the file you're running //then you use it as follows: $tm->s(); //put all you PHP code and site code in here $tm->e(); //and it will display the execute time in seconds to 6 decimal places. Generally i get results such as 0.000158 //just stay aware that php is extremely fast so if it's a small piece of code you'll get lots of 0s on the left ?> |
|
|
|
Jul 5 2006, 11:57 PM
Post
#2
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 10 Joined: 5-July 06 Member No.: 26,142 |
As my knowledge of PHP increases, I have learned more, in this version, I use a class. V1: http://www.trap17.com/forums/page-loading-time-t4782.html CODE <?php class microtimer { // Starts, Ends and Displays Page Creation Time function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function s() { $this->st = $this->getmicrotime(); } function e() { $this->et = $this->getmicrotime(); echo round(($this->et - $this->st), 6); } } $tm = new microtimer; //A class is a collective function set. Stick that in a file that's included or in the file you're running //then you use it as follows: $tm->s(); //put all you PHP code and site code in here $tm->e(); //and it will display the execute time in seconds to 6 decimal places. Generally i get results such as 0.000158 //just stay aware that php is extremely fast so if it's a small piece of code you'll get lots of 0s on the left ?> tnx man |
|
|
|
Jul 6 2006, 09:34 AM
Post
#3
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
Ah so the original one is not accurate? I put it on my wap site but use explode to get rid of the E. I had a feeling the start needed to be at the top of code and vice versa lol. Ah well it still looks cool untill i use the new code. Im sure on php.net i read a way to shorten strings.. I will look again at some point as for my tiny wap site the number seems very long, i would have maybe just like 1.65824 ;-)
|
|
|
|
Jul 6 2006, 01:41 PM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 933 Joined: 24-August 04 Member No.: 892 |
If you wnat the number to have less numbers after its decimal place, simple edit this code
CODE function e() {
$this->et = $this->getmicrotime(); echo round(($this->et - $this->st), 6); //Change this number here } |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 13th October 2008 - 10:43 PM |