php查询mongodb和mysql的效率对比

2013-11-08 12:47 来源:www.chinab4c.com 作者:ecshop专家

 

    php查询mongodb和mysql的效率对比,我们可以考虑把大量的ecshop规格放到mongodb里面,这样可以支持百万级别的数据。以下是php查询mongodb和mysql的效率对比对比代码和结果

  
$conn = new  Mongo("mongodb://admin:admin@localhost/images");
$db = $conn->selectDB("images");
$tab = $db->img;
/*for ($i=1;$i<50;$i++) {
    $size = 100000;
    $start = ($i-1)*$size;;
   
    $sql = "select * from ".tname('imgs')." limit $start,$size";
    $res = $img_db->query($sql);
    while($row = $img_db->fetch_array($res)) {
        $tab->insert($row);
    }

}*/

$goods_name ='MKT1813333405';
$a = microtime_float();
$res = $tab->findOne(array('goods_name'=>$goods_name));

echo microtime_float()-$a;
echo "<br>";
$c = microtime_float();;
$row = $img_db->getRow("select * from ".tname('imgs')." where goods_name='$goods_name'");

echo microtime_float()-$c;echo "<br>";
echo "ok";

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
  0.000128984451294

  0.00198793411255

来源:http://www.chinab4c.com