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条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿