Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Page Loading Time V2, how long does your page take to load?
cragllo
post 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
?>
Go to the top of the page
 
+Quote Post
B4ND1T
post Jul 5 2006, 11:57 PM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 10
Joined: 5-July 06
Member No.: 26,142



QUOTE(cragllo @ Jul 5 2006, 03:47 PM) *

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
Go to the top of the page
 
+Quote Post
wappy
post 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 ;-)
Go to the top of the page
 
+Quote Post
cragllo
post 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
    }
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Page Loading Time(7)
  2. Help Php: How To Load String From Text File (solved)(9)


 



- Lo-Fi Version Time is now: 13th October 2008 - 10:43 PM