Benchmark - MYSQL vs MYSQLi
11th Jun 2007I was in the shower after a hot day and i was thinking about how the php.net site explains that this MYSQLi is the improved version to the MYSQL function.
So i've decided that a little investigation in weather it can connect,query and close faster than the MYSQL function I preferr the MYSQLi version as the _connect function is a lot more organised with the DB select in it.
Code used for benchmark
Below are the two files which were used in my benchmark test
mysql.php(169 bytes)
<?php
$i = mysql_connect('localhost','root','');
mysql_select_db('php_benchmark',$i);
mysql_query('SELECT `article` FROM benchmark',$i);
mysql_close($i);
?>
<?php
$i = mysqli_connect('localhost','root','','php_benchmark');
mysqli_query($i,'SELECT `article` FROM benchmark');
mysqli_close($i);
?>
The results
Out of the 1500 tests i made for each page the following is listed below; There was 100 rows in the table
| Structure | Mean | Median | Max |
|---|---|---|---|
| MYSQL | 301 milliseconds | 206 milliseconds | 2202 milliseconds |
| MYSQLi | 317 milliseconds | 298 milliseconds | 1902 milliseconds |
Conclusion
Overall MYSQL wins by over 92 milliseconds. MYSQL has its disadvantage over MYSQLi as it was the slowest to return the results out of the both.
I would of thought that MYSQLi would of beat it but i guess not, also dont it just look alot neater! ah well