/**
* function lib
*/
function conn(){
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
$conn = mysql_connect($host, $user, $pass);
if (!$conn || !is_resource($conn)){
die("Connect to mysql failed: ". mysql_error());
}
mysql_select_db($db);
return $conn;
}
function query($conn, $sql){
$res = mysql_query($sql, $conn);
if (!$res){
echo mysql_error()." ";
return false;
}
return true;
}
function get_data($conn, $sql){
$res = mysql_query($sql, $conn);
if (!$res){
echo mysql_error()." ";
return false;
}
$result = array();
while($row = mysql_fetch_array($res)){
$result[] = $row;
}
return $result;
}
function get_time()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
/**
* Insert test
*/
$conn = conn();
$count = 200000;
//Heap engine
$s1 = get_time();
for($i=0; $i<$count; $i++){
query($conn, "insert into tbl_heap set name = 'heiyeluren',
, summary='This
message is summary'");
}
$e1 = get_time();
echo "Heap engine insert $count record used time: ". ($e1-$s1) ." ";
//MyISAM engine
$s2 = get_time();
for($i=0; $i<$count; $i++){
query($conn, "insert into tbl_isam set name = 'heiyeluren',
, summary='This
message is summary'");
}
$e2 = get_time();
echo "MyISAM engine insert $count record used time: ". ($e2-$s2) ." ";
/**
* Select test
*/
$count = 1000;
$records = 10000;
$s1 = get_time();
for($i=0; $i<$count; $i++){
$res = get_data($conn, "select * from tbl_heap limit $records");
unset($res);
}
$e1 = get_time();
echo "Heap engine select $count record used time: ". ($e1-$s1) ." ";
$s2 = get_time();
for($i=0; $i<$count; $i++){
$res = get_data($conn, "select * from tbl_isam limit $records");
unset($res);
}
$e2 = get_time();
echo "MyISAM engine select $count record used time: ". ($e2-$s2) ." ";
?>