douhe4608 2012-03-13 13:56
浏览 48
已采纳

为什么PHP运行速度比MySQL快[关闭]

I ran some simple tests: same complex query in mysql and php and measured the times taken to process them. The results are very controversial and suggest that some queries PHP processes faster than MySql.

In theory, shouldn't be the MySql faster? I am want compare how PHP (scripting language) interface decreases the performance of complex SQL query. But why my results suggest otherwise?

Those are averages, I run each query 3 times!

php code:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test3", $con);

    $start = microtime(TRUE);
    $result = mysql_query("SELECT * FROM `test`
    ORDER BY `test`.`test1` DESC
    LIMIT 0,100");


echo "<table border='1'>
<tr>
<th>ID</th>
<th>test1</th>
<th>test2</th>
<th>test3</th>
<th>test4</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['Test1'] . "</td>";
  echo "<td>" . $row['Test2'] . "</td>";
  echo "<td>" . $row['Test3'] . "</td>";
  echo "<td>" . $row['Test4'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

$end = microtime(TRUE);

$sqlTime = $end - $start;


mysql_close($con);
echo $sqlTime
?> 

The results: time in seconds against the number of records: enter image description here

  • 写回答

2条回答 默认 最新

  • duanke8011 2012-03-13 14:44
    关注

    I can see you are using phpmyadmin, it is scripted too to return the values.This might be slow than the speed of your script which is definitely small. Did you consider to run the mysql queries from the command prompt?This might give you a clear difference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度