Skip to content

Instantly share code, notes, and snippets.

@jacobbridges
Last active August 29, 2015 14:08
Show Gist options
  • Save jacobbridges/f96d373c515ea3852e23 to your computer and use it in GitHub Desktop.
Save jacobbridges/f96d373c515ea3852e23 to your computer and use it in GitHub Desktop.
Track PHP Execution Time
<?php
// The 'microtime' code can be included in any method or application to track the script run time.
function test()
{
// Get the (negative) current UNIX timestamp in milliseconds
$time = -microtime(true);
// Run some code
$hash = 0;
for ($i=0; $i < rand(1000,4000); ++$i)
{
$hash ^= md5(substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, rand(1,10)));
}
// Add the current UNIX timestamp to the previous (negative) timestamp
$time += microtime(true);
// Print out an execution message
echo "Hash: $hash iterations: " . sprintf('%0.4f', $time) . " seconds: ";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment