I am testing my php code to try and see which coding methods result in quickest execution. I want to eventually test all of my php code which needs testing to try and create the most rapidly-executed code that I can. I am starting with a simple example on my home page, using microtime() to record the time before an INSERT statement executes and the time after it executes, and then echoing the difference as follows:
//Lots of code
$microtime1 = microtime();
$sql1=("INSERT INTO Table (value1,value2,value3,value4,value5,value6,value7) VALUES
('$value1','$value2', '$value3', '$value4', '$value5', '$value6', 'value7' )");
if (mysqli_query($sql1)) {
$microtime2 = microtime();
$Difference = $microtime2 - $microtime1;
echo "<SCRIPT>
alert('$Difference');
location = 'home.php';
</SCRIPT>";
} else {
$message = 'The site is having some technical difficulties. Please try again!";
echo "<SCRIPT>
alert('$message');
location = 'home.php';
</SCRIPT>";
}
//More code
Over 10 trials, I initiated this query by inputting the same 3 letter string ('ddd') into the same input text box and clicking the same button (with no other users logged besides me), recording $Difference each time. I am astonished at how much variance there is in the data. For these 10 trials, the standard deviation in $Difference was 40% of the mean value of $Difference. Is there a better way to do this that I am not aware of? Or will I have to do 10-20 trials for each function to get a usable mean value of $Difference for my other code?