Given how slow your queries are running you might not want to run them very many times, but I found this old script I used for testing. It uses the now-deprecated mysql extension rather than mysqli, but it could easily be modified:
define("DB_HOST", "localhost");
define("DB_NAME", "my_database");
define("DB_USER", "db_user");
define("DB_PASS", "*****");
mysql_connect(DB_HOST, DB_USER, DB_PASS)
or die("db connection failed");
mysql_select_db(DB_NAME)
or die("db select failed.");
function clear_query_cache() {
mysql_query("RESET QUERY CACHE;")
or die("failed to reset query cache");
}
define("TOTAL_RUNS", 1000);
// define the query you want to test here
$sql = "SELECT col1, col2, col3 FROM my_table";
$total_elapsed_time = 0;
for($i=0; $i<TOTAL_RUNS; $i++) {
// clear the query cache
clear_query_cache();
// run the query and time it
$start = microtime(TRUE);
mysql_query($sql)
or die("query failed: " . mysql_error());
$end = microtime(TRUE);
$total_elapsed_time += ($end-$start);
}
echo "\nQuery run: " . $sql . "\n\n";
echo "Times: " . TOTAL_RUNS . "\n";
echo "Elapsed time:" . $total_elapsed_time . "\n";
echo "Time per query:" . ($total_elapsed_time / TOTAL_RUNS) . "\n";