I have been testing prepared statements on MySQLi - extension.
Code: Select all
echo "MySQLi OO STMT: ";
$c = new mysqli('localhost','root','hottis','test');
$time = time()+microtime(1);
$stmt = $c -> stmt_init();
for ($loop = 0;$loop < 500;$loop++)
{
$stmt -> prepare('SELECT username FROM admins WHERE id=1');
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($a);
$stmt -> fetch();
}
$stmt -> close();
echo (time()+microtime(1)-$time) .' seconds. Result: ';
echo "$a\n";Code: Select all
echo "MySQLi P Norm: ";
$c = mysqli_connect('localhost','root','hottis','test') or die('eh');
$time = time()+microtime(1);
for ($loop = 0;$loop < 500;$loop++)
{
$r = mysqli_query($c,'SELECT username FROM admins WHERE id=1');
$a = mysqli_fetch_row($r);
}
echo (time()+microtime(1)-$time) .' seconds. Result: ';
echo "$a[0]\n";I am pretty amazed by these figures... prepared statements are 1.65x slower than normal procedural queries... weren't they supposed to be faster?MySQL P Norm: 0.045994758605957 seconds. Result: admin
MySQLi OO STMT: 0.076005935668945 seconds. Result: admin
Or did I write something wrong?