php和asp.net下SQLite3的执行速度对比

当看到这样的结果时,我很诧异。我以为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;
        }

    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值