我对MongoDb非常兴奋并且最近一直在测试它.我在MySQL中有一个名为posts的表,大约有2000万条记录仅在名为"id"的字段上编入索引.
我想比较MongoDB的速度,我运行了一个测试,它将从我们庞大的数据库中随机获取和打印15条记录.我为mysql和MongoDB运行了大约1000次查询,我很惊讶我没有注意到速度上的很多差异.也许MongoDB快了1.1倍.这非常令人失望.有什么我做错了吗?我知道我的测试并不完美,但是当涉及阅读密集的杂务时,MySQL与MongoDb相当.
注意:
用于测试MongoDB的示例代码
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_taken = 0;
$tries = 100;
// connect
$time_start = microtime_float();
for($i=1;$i<=$tries;$i++)
{
$m = new Mongo();
$db = $m->swalif;
$cursor = $db->posts->find(array('id' => array('$in' => get_15_random_numbers())));
foreach ($cursor as $obj)
{
//echo $obj["thread_title"] . "<br><Br>";
}
}
$time_end = microtime_float();
$time_taken = $time_taken + ($time_end - $time_start);
echo $time_taken;
function get_15_random_numbers()
{
$numbers = array();
for($i=1;$i<=15;$i++)
{ …
Run Code Online (Sandbox Code Playgroud)