$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’,
email=’heiyeluren@abc.com’, 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’,
email=’heiyeluren@abc.com’, 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) .\" \";
?>
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/