当看到这样的结果时,我很诧异。我以为php会更快一点儿,但事实是asp.net更胜一筹。不解!
php 页面:0.5秒
asp.net 页面 :0.4秒
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();
?>
$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 "2012Beta 5.0总下载量:".$row[0]."";
*/
$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 "
printf("
%s%s%s%s%s%s%s%s\n",
"网吧名","电话","邮箱","QQ","IP","物理位置","安装时间","服务商");
$result=$db->query($sql); //执行查询语句
while($row = $result->fetchArray()){
printf("
%s%s%s%s%s%s%s%s\n",
$row["网吧名"],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7]);
}
echo "
";
$db->close(); //关闭
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "花费时间:$time 秒\n";
?>
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;
///
///
///
///
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;
}
}
}