Monkuar Posted March 9, 2012 Share Posted March 9, 2012 I want to do a test while refreshing the page 100 times with 500 rows in a table, and then without 500 rows in a table and with different kind of php code, i need to do some type of testing to get results back in to show which way is faster for mysql/php. Any idea how to do this any scripts out there or a built in php/mysql function? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/ Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 Simply add some code at the beginning of the script to get microtime() then do the same thing at the end of the script. Then take the difference. Also, unless you want to manually write down the results on each test, you probably want to store the results somewhere. Just add that to the script AFTER you have already taken the final time. Look at example #1 for the microtime() function: http://php.net/manual/en/function.microtime.php for an example of how you could implement this. Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325647 Share on other sites More sharing options...
Monkuar Posted March 9, 2012 Author Share Posted March 9, 2012 Simply add some code at the beginning of the script to get microtime() then do the same thing at the end of the script. Then take the difference. Also, unless you want to manually write down the results on each test, you probably want to store the results somewhere. Just add that to the script AFTER you have already taken the final time. Look at example #1 for the microtime() function: http://php.net/manual/en/function.microtime.php for an example of how you could implement this. does this microtime feature/etc benchmark query performance too? I mean when it echos out in miliseconds the time it takes for a refresh, does that count the mysq queries too? or just php Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325650 Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 does this microtime feature/etc benchmark query performance too? I mean when it echos out in miliseconds the time it takes for a refresh, does that count the mysq queries too? or just php Not exactly, microtime() is simply to get the current timestamp in milliseconds. So, if you capture microtime() two time you can calculate the amount of time it took to perform the tasks between those two instances. You can even capture the time in multiple instances of the script to determine performance of specific things in the script. Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325652 Share on other sites More sharing options...
Monkuar Posted March 9, 2012 Author Share Posted March 9, 2012 does this microtime feature/etc benchmark query performance too? I mean when it echos out in miliseconds the time it takes for a refresh, does that count the mysq queries too? or just php Not exactly, microtime() is simply to get the current timestamp in milliseconds. So, if you capture microtime() two time you can calculate the amount of time it took to perform the tasks between those two instances. You can even capture the time in multiple instances of the script to determine performance of specific things in the script. $begin = microtime(true); //true returns the microtime as a float value, so we can do maths with it. Without this, it'd return a string and need typecasting, or otherwise over complicate it... //write some awesome, fast PHP code here. $end = microtime(true); //we've discussed this. echo "Time taken: ", $end - $begin; So for this, on my forum software I am making, I should put $end = microtime(true); at the bottom of the global footer to get the correct time. Then can I store that and write it into a text file using $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Floppy Jalopy\n"; fwrite($fh, $stringData); $stringData = "Pointy Pinto\n"; fwrite($fh, $stringData); fclose($fh); something like that to store the seconds? then I can refresh page 100 times and get then look at the results? Would that be a fair benchmark imo or? Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325654 Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 Yes. Just put the start and end times around the specific things you want to benchmark. You can even gather multiple times to gather metrics on different sections of code. You might also want to looking into using EXPLAIN to optimize your queries http://dev.mysql.com/doc/refman/5.1/en/using-explain.html Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325658 Share on other sites More sharing options...
Monkuar Posted March 9, 2012 Author Share Posted March 9, 2012 Yes. Just put the start and end times around the specific things you want to benchmark. You can even gather multiple times to gather metrics on different sections of code. You might also want to looking into using EXPLAIN to optimize your queries http://dev.mysql.com/doc/refman/5.1/en/using-explain.html sweetbro, Thank you $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $time_diff); fclose($fh); Now $time_diff is my milisecond variable to show how many ms it is, But how do I make it so it doesn't change the whole file and replace it with the milisecond, I need it to add the data below data inside a text file. What it does is every refresh it changes it "0.0106" I Need it to do "0.0106 0.0101 ,so on" so it stores the stuff. Cant seem to find out with fwrite to accomplish this fwrite($fh, $time_diff."\n"); fixed ty topic solved Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325661 Share on other sites More sharing options...
DavidAM Posted March 9, 2012 Share Posted March 9, 2012 fopen($myFile, 'a'); The "a" tells it to append to the file if it exists. See the manual for fopen. Quote Link to comment https://forums.phpfreaks.com/topic/258606-how-to-do-a-mysqlphp-performance-test/#findComment-1325671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.