query('DELETE FROM tt'); } function test_non_prep($con) { delete($con); $t1 = microtime(true); for($i = 0; $i < N; $i++) { $s = 'Some text bla bla bla'; $stmt = $con->query("INSERT INTO tt VALUES ($i, '$s')"); } $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Non prepared: $dt\r\n"; } function test_prep_sing($con) { delete($con); $t1 = microtime(true); for($i = 0; $i < N; $i++) { $stmt = $con->prepare('INSERT INTO tt VALUES (?, ?)'); $s = 'Some text bla bla bla'; $stmt->bind_param('is', $i, $s); $stmt->execute(); $stmt->close(); } $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Prepared not reused: $dt\r\n"; } function test_prep_multi($con) { delete($con); $t1 = microtime(true); $stmt = $con->prepare('INSERT INTO tt VALUES (?, ?)'); for($i = 0; $i < N; $i++) { $s = 'Some text bla bla bla'; $stmt->bind_param('is', $i, $s); $stmt->execute(); } $stmt->close(); $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Prepared reused: $dt\r\n"; } $con = new mysqli('localhost', 'root', '', 'Test'); test_non_prep($con); test_prep_sing($con); test_prep_multi($con); $con->close(); ?>