Find script execution time using php


Abhi's Blog

//place this before any script you want to calculate time
$time_start = microtime(true);

//sample script
for($i=0; $i<1000; $i++){
//do anything
}

$time_end = microtime(true);

//dividing with 60 will give the execution time in minutes other wise seconds
$execution_time = ($time_end – $time_start)/60;

// Convert time in human readable format

$sec = intval($execution_time);
$micro = $execution_time – $sec;
$final_execution = strftime(‘%T’, mktime(0, 0, $sec)) . str_replace(‘0.’, ‘.’, sprintf(‘%.3f’, $micro));

//execution time of the script
echo ‘<b>Total Execution Time:</b> ‘.$final_execution.’ Mins’;

// Script end

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s