It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum Script-archive

PHP Efficiency Testing - Measuring Script Execution Times

Share your completed scripts.

Moderator: Malcolm

PHP Efficiency Testing - Measuring Script Execution Times

Postby HotNoob on Wed Sep 22, 2010 3:18 am

Php Efficiency - Measuring Script Execution Times

Eventually, you will get to a point where your script's become large, bulky, and long loading. So now you need a method to help you figure out, what is better? to load it this way or that way? Because, we all don't know exactly how efficient every possible function and combination of functions is.

So here is an example of how to measure script execution times

Code: Select all
<?php
//this is the first half of the script, simply place it where you wish to start measuring the time.
                      $time = microtime();
                      $time = explode(' ', $time);
                      $time = $time[1] + $time[0];
                      $start = $time;
?>

Code: Select all
//After the portion of your script has run, simply add this piece of code;
                      $time = microtime();
                      $time = explode(' ', $time);
                      $time = $time[1] + $time[0];
                      $finish = $time;
                      $total_time = round(($finish - $start), 4); // i doubt you need it more exact than milliseconds
//in this example, the script is measuring the amount of time it took to search a database and output the results
                      echo '<p style="font-size: 12px; color: grey;">Search Results Generated in '.$total_time.' seconds.</p>'."\n";



Enjoy.
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am

Re: PHP Efficiency Testing - Measuring Script Execution Times

Postby webmaster on Wed Sep 22, 2010 5:11 am

Great post!
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden


Who is online

Users browsing this forum: No registered users and 0 guests