Created
June 29, 2017 10:26
-
-
Save amon-ra/6480f89dd75c9d5713306ce3de297cb2 to your computer and use it in GitHub Desktop.
PHP simpliest profiling
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 | |
prof_flag("Start"); | |
include '../lib/database.php'; | |
include '../lib/helper_func.php'; | |
prof_flag("Connect to DB"); | |
connect_to_db(); | |
prof_flag("Perform query"); | |
// Get all the data | |
$select_query = "SELECT * FROM data_table"; | |
$result = mysql_query($select_query); | |
prof_flag("Retrieve data"); | |
$rows = array(); | |
$found_data=false; | |
while($r = mysql_fetch_assoc($result)) | |
{ | |
$found_data=true; | |
$rows[] = $r; | |
} | |
prof_flag("Close DB"); | |
mysql_close(); //close database connection | |
prof_flag("Done"); | |
prof_print(); | |
?> |
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 | |
// Call this at each point of interest, passing a descriptive string | |
function prof_flag($str) | |
{ | |
global $prof_timing, $prof_names; | |
$prof_timing[] = microtime(true); | |
$prof_names[] = $str; | |
} | |
// Call this when you're done and want to see the results | |
function prof_print() | |
{ | |
global $prof_timing, $prof_names; | |
$size = count($prof_timing); | |
for($i=0;$i<$size - 1; $i++) | |
{ | |
echo "<b>{$prof_names[$i]}</b><br>"; | |
echo sprintf(" %f<br>", $prof_timing[$i+1]-$prof_timing[$i]); | |
} | |
echo "<b>{$prof_names[$size-1]}</b><br>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment