一共有3093326条企业数据,其中sphinx代码如下:
<?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); $s = new SphinxClient; $s->setServer("localhost", 9312); $s->setMatchMode(SPH_MATCH_ANY); $s->setMaxQueryTime(300); $result = $s->query("暖气片",'test1'); var_dump($result); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Sphinx search in $time seconds "; ?>
php+mysql代码如下:
<?php $start = microtime_float(); mysql_connect("localhost", "root", "root") or die("Could not connect: " . mysql_error()); mysql_select_db("test"); $result = mysql_query("SELECT id, cache_companyname as title, content FROM pb_trades where cache_companyname like '%暖气片%' or content like '%暖气片%' limit 10"); echo mysql_num_rows($result); $end = microtime_float(); $time = $end - $start; echo "Mysql like search in $time seconds "; mysql_free_result($result); ?>
都是搜索带有“暖气片”的关键词,Sphin花费0.17000985145569 seconds,Mysql花费了19.646124124527 seconds.