Last active
August 29, 2015 14:08
-
-
Save jacobbridges/f96d373c515ea3852e23 to your computer and use it in GitHub Desktop.
Track PHP Execution Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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