新鲜出炉,ADO.NET与ADO速度测试!!!

icyer 2002-01-15 04:39:10
测试环境:
Windows 2000 SP2, Visual Studio .NET Beta2, SQL Server 7.0
测试项目:
ADO.NET 的System.Data.SqlClient
ADO.NET 的System.Data.OleDb
ADO 2.7 (从"引用"中添加"COM"的"\Program Files\Common Files\System\ado\msado15.dll")
测试代码:
1. ADO.NET 的System.Data.SqlClient
Dim timer As DateTime = Now()
Dim tconn As New SqlClient.SqlConnection("Data Source=db;User ID=sa;Password=;Initial Catalog=pubs;")
tconn.Open()
Dim tcmd As New SqlClient.SqlCommand()
tcmd.Connection = tconn
tcmd.CommandType = CommandType.Text
Dim m As Integer, strcmd As String
For m = 0 To 10000
strcmd = "insert into tbTest values ('" & m.ToString & "'," & m.ToString & ")"
tcmd.CommandText = strcmd
tcmd.ExecuteNonQuery()
Next
Dim timer1 As DateTime = Now()
lblMsg.Text = timer1.ToLongTimeString & "---" & timer.ToLongTimeString
用时:17秒!!!

2. ADO.NET 的System.Data.OleDb
Dim timer As DateTime = Now()
Dim tconn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Data Source=db;User ID=sa;Password=;Initial Catalog=pubs;")
tconn.Open()
Dim tcmd As New OleDb.OleDbCommand()
tcmd.Connection = tconn
tcmd.CommandType = CommandType.Text
Dim m As Integer, strcmd As String
For m = 0 To 10000
strcmd = "insert into tbTest values ('" & m.ToString & "'," & m.ToString & ")"
tcmd.CommandText = strcmd
tcmd.ExecuteNonQuery()
Next
Dim timer1 As DateTime = Now()
lblMsg.Text = timer1.ToLongTimeString & "---" & timer.ToLongTimeString
用时:32秒!!

3. ADO 2.7
Dim timer As DateTime = Now()
Dim adoconn As New ADODB.Connection()
adoconn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=db;User ID=sa;Password=;Initial Catalog=pubs;"
adoconn.Open()
Dim adocmd As New ADODB.Command()
adocmd.ActiveConnection = adoconn
adocmd.CommandType = ADODB.CommandTypeEnum.adCmdText
Dim m As Integer, strcmd As String
For m = 0 To 10000
strcmd = "insert into tbTest values ('" & m.ToString & "'," & m.ToString & ")"
adocmd.CommandText = strcmd
adocmd.Execute()
Next
Dim timer1 As DateTime = Now()
lblMsg.Text = timer1.ToLongTimeString & "---" & timer.ToLongTimeString
用时:84秒!

结论就不必我说了吧。
补充一点:
我的机器配置是PIII 450,128M,华硕815EP,30GB。
当前运行程序:Visual Studio .NET Beta2, SQL Server 7.0
没次测试之后都把tbTest全部清空。
tbTest中有两个字段:varchar的Field1,int的Field2。

此测试结果只是大概结果。
...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hfyun 2002-02-04
  • 打赏
  • 举报
回复
Amey说的有道理,效率与兼容性总是一对矛盾。
Amey 2002-01-31
  • 打赏
  • 举报
回复
sqlclient--为对mssqlserver设计

oledb--为各种 db 设计--如oracle...
icyer 2002-01-25
  • 打赏
  • 举报
回复
lblMsg.Text = timer1.ToLongTimeString & "---" & timer.ToLongTimeString
lessbird 2002-01-24
  • 打赏
  • 举报
回复
测试时间长短怎么看?
DragonInChina 2002-01-23
  • 打赏
  • 举报
回复
但我試了之后﹐總覺得要取一些資料﹐總是需等很久一段時間﹐感覺上不及ADO,各位大蝦﹐你們用過之后﹐感覺怎樣﹖
yangbit 2002-01-22
  • 打赏
  • 举报
回复
对头,我也觉得sqlclient比oledb快一点。
icyer 2002-01-15
  • 打赏
  • 举报
回复
还有一点关键的忘了说:
我是在ASP.NET中测试的。IIS5.0。
以上代码均写到一个Button_Click事件中,每次编译后先刷新页面,再按Button。

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧