一.建立數據庫BigTest
ID int 主鍵 自增
Title varchar(100)
ReadNum int
二.向數據庫中插入100萬條數據
declare @i int
set @i=1
while @i<=500000
begin
insert into LIEzui_Test(Title,ReadNum) values('執行總數統計',@i)
set @i=@i+1
end
GO
declare @i int
set @i=1
while @i<=500000
begin
insert into LIEzui_Test(Title,ReadNum) values('毛巾因經常處於潮濕狀態而極易滋生有害細菌',@i)
set @i=@i+1
end
GO
三.開始測試
首先在頁面內放一個repeater,一個DataList,一個GridVIEw用於綁定數據 三個label 用於顯示結果
首先測試repeater
代碼如下:
DataTable dt = Jinlong.Data.DBHelper.ReturnDataTable("Select Top 10000 * From BigTest Where Title Like '%執行%'");
Stopwatch st = new Stopwatch();
st.Start();
Repeater1.DataSource = dt;
Repeater1.DataBind();
st.Stop();
Label1.Text = st.ElapsedMilliseconds.ToString() + "ms";
結果如下:
repeater:
94ms
151ms
141ms
146ms
131ms
94ms
132ms
然後測試DataList
DataTable dt = Jinlong.Data.DBHelper.ReturnDataTable("Select Top 10000 * From BigTest Where Title Like '%執行%'");
Stopwatch st2 = new Stopwatch();
st2.Start();
DataList1.DataSource = dt;
DataList1.DataBind();
st2.Stop();
Label2.Text = st2.ElapsedMilliseconds.ToString() + "ms";
結果如下:
DataList
139ms
90ms
159ms
113ms
136ms
137ms
87ms
最後測試GridvIEw
DataTable dt = Jinlong.Data.DBHelper.ReturnDataTable("Select Top 10000 * From BigTest Where Title Like '%執行%'");
Stopwatch st3 = new Stopwatch();
st3.Start();
GridVIEw1.DataSource = dt;
GridVIEw1.DataBind();
st3.Stop();
Label3.Text = st3.ElapsedMilliseconds.ToString() + "ms";
GridvIEw
326ms
339ms
450ms
297ms
311ms
275ms
360ms
結果對比
Repeater DataList GridVIEw
94ms 139ms 326ms
151ms 90ms 339ms
141ms 113ms 450ms
146ms 136ms 297ms
131ms 137ms 311ms
94ms 139ms 275ms
132ms 87ms 360ms
結論:Repeater和DataList 差不多,GridVIEw明顯慢很多