php和asp.net下SQLite3的执行速度对比
2011-12-10 19:05
393 查看
当看到这样的结果时,我很诧异。我以为php会更快一点儿,但事实是asp.net更胜一筹。不解!
php 页面:0.5秒
asp.net 页面 :0.4秒
php页面源码
asp.net 页面源码
php 页面:0.5秒
asp.net 页面 :0.4秒
php页面源码
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <body> <?php /** * Simple function to replicate PHP 5 behaviour */ function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); ?> <?php $filepath="F:\MyPram\DAQ\u7pkDAQ.db3"; $db=new SQLite3($filepath); //打开此路径数据库文件 /* $sql="select count(ip) from downloadinfo where netbarname like '%(NEW 2012(Beta5.0))%' "; $result=$db->query($sql); //执行查询语句 $row = $result->fetchArray(); echo "<font color=blue>2012Beta 5.0总下载量:".$row[0]."</font>"; */ $sql="select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta5.0))%' order by time desc"; //查询记录 echo "<table cellspacing='0' cellpadding='3' rules='all' style='background-color:White;border-color:#CCCCCC;border-width:1px;border-style:None;font-size:10pt;font-weight:normal;border-collapse:collapse;'>"; printf("<tr style='color:White;background-color:#006699;font-weight:bold;'><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", "网吧名","电话","邮箱","QQ","IP","物理位置","安装时间","服务商"); $result=$db->query($sql); //执行查询语句 while($row = $result->fetchArray()){ printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $row["网吧名"],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7]); } echo "</table>"; $db->close(); //关闭 $time_end = microtime_float(); $time = $time_end - $time_start; echo "花费时间:$time 秒\n"; ?> </body> </html>
asp.net 页面源码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SQLite; namespace DAPX { public partial class DownloadList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string strOutput; long iStartMs = DateTime.Now.Ticks; long iEndMs = 0; //if (!this.IsPostBack) //{ strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); conn = new System.Data.SQLite.SQLiteConnection(); conn.ConnectionString = strConn; conn.Open(); //---------------------------------------------- string strSQL = string.Empty; int index = Convert.ToInt32(Request.QueryString["index"]); switch (index) { case 1: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW2012 Beta1.0)%' order by time desc"; break; case 2: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta2.0))%' order by time desc"; break; case 3: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta3.0))%' order by time desc"; break; case 4: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta4.0))%' order by time desc"; break; case 5: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta5.0))%' order by time desc"; break; default: strSQL = "select NetBarName as 网吧名, Telephone as 电话, Email as 邮箱,QQ,IP,Zone as 物理位置,Time as 使用时间, net as 网络服务商 from downloadinfo where netbarname like '%(NEW 2012(Beta5.0))%' order by time desc"; break; } this.GridView1.DataSource = GetDataTable(strSQL); DataBind(); //---------------------------------------------- conn.Close(); //} //else // DataBind(); iEndMs = DateTime.Now.Ticks; strOutput = string.Format("花费时间:{0}\n", (iEndMs - iStartMs) * System.Math.Pow(10, -7)); Response.Write(strOutput); } System.Data.SQLite.SQLiteConnection conn = null; System.Data.SQLite.SQLiteDataAdapter adapter = null; System.Data.SQLite.SQLiteCommand cmd = null; string strConn = string.Empty; /// <summary> /// /// </summary> /// <returns></returns> public DataTable GetDataTable(string strSQL) { // string strSQL = string.Empty; DataTable dttTmp = null; string strTmp = string.Empty; if (conn.State == ConnectionState.Open) { cmd = new SQLiteCommand(conn); //总下载量 //strSQL = "select count(*) from downloadinfo "; cmd.CommandText = strSQL; adapter = new SQLiteDataAdapter(cmd); dttTmp = new DataTable(); adapter.Fill(dttTmp); if (dttTmp != null) return dttTmp; } return null; } } }
相关文章推荐
- 从ASP.NET的PHP执行速度比较谈起
- 从ASP.NET的PHP执行速度比较谈起
- 从ASP.NET的PHP执行速度比较谈起
- 艾伟_转载:从ASP.NET的PHP执行速度比较谈起
- 盘点 PHP 和 ASP.NET 的10大对比!
- ASP.NET和PHP全面对比
- Asp.net Mvc对比Php的4大误解
- ASP.NET和PHP全面对比
- 盘点 PHP 和 ASP.NET 的10大对比!
- ASP.NET 比拼 PHP,谁将是速度之王?
- ASP.NET和PHP性能对比
- PHP 5+MySQL+SQLite+Zend+ASP+ASP.NET+Perl+CGIOpenSSL的服务器一个软件搞定
- 浅析ASP.NET比拼PHP,谁是速度之王?
- ASP.NET比拼PHP,谁是速度之王?
- ASP.NET和PHP全面对比
- ASP.net与PHP两大网站开发架构优势对比
- ASP.NET比拼PHP,谁是速度之王?(转)
- ASP.NET和PHP性能对比整理和翻译
- java,php,asp,asp.net,ror等几种Web技术对比(第一版本)
- 盘点PHP和ASP.NET的10大对比!