SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member steve-h's Avatar
    Join Date
    Feb 2002
    Location
    Southampton UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Timing a php script in milliseconds

    I am doing a bit of research and comparing download times between ASP reading an Access database or text file and PHP reading from a MySQL database and a text file. In ASP I can call a function to get the time at the beginning and end of the script and simply subtract one from the other. I get a nice read out for sub 1 second as it is accurate to several decimal places.

    However I haven't been able to pull the same trick with PHP. I am calling the time() function but it only returns in seconds. Since the read from mySQL is so fast I need something more accurate.

    Any one care to help me out

  2. #2
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this code
    PHP Code:
    <?php    
        
    function getmicrotime()
        {
            
    $arr explode(" ",microtime());
            return 
    $arr[0] + $arr[1];
        }
        
    $start getmicrotime();
        for(
    $i=0$i 1000$i++)
        {
            print 
    " ";
        }
        
    $stop getmicrotime();

        print 
    "Start time $start <br>";
        print 
    "End time $stop <br><br>";
        print 
    "Total use time ".($stop $start)."  second ";
    ?>
    I live in Thailand. My English grammar not well.

  3. #3
    SitePoint Member steve-h's Avatar
    Join Date
    Feb 2002
    Location
    Southampton UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Nice one. That little function works a treat.

    Ta mucho!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •