Jump to content

How to do a MYSQL/PHP performance test?


Monkuar

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.