ADO.NET - 连接池性能
2008-08-12 11:53
337 查看
连接池性能测试代码如下:
1.连接池设置为True
耗时:00:00:00.4972304
2.连接池设置为False
耗时:00:00:43.6183675
1 using System.Diagnostics;
2
3 using System.IO;
4
5
6 SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
7
8 builder.DataSource = "127.0.0.1";
9
10 builder.InitialCatalog = "database";
11
12 builder.UserID = "user";
13
14 builder.Password = "user";
15
16 builder.Pooling = true;
17
18 //builder.MaxPoolSize = 3;
19
20 //builder.MinPoolSize = 2;
21
22 SqlConnection con = new SqlConnection(builder.ConnectionString);
23
24 SqlCommand com = con.CreateCommand();
25
26
27 Stopwatch sw = new Stopwatch();
28
29 sw.Start();
30
31
32 for (int i = 1; i <= 10000; i++)
33
34 {
35
36 con.Open();
37
38 con.Close();
39
40 }
41
42
43 sw.Stop();
44
45 TimeSpan ts = sw.Elapsed;
46
47
48 string tie = ts.ToString();
49
50 StreamWriter swe = File.CreateText("test.txt");
51
52 swe.WriteLine(tie);
53
54 swe.Close();
55
1.连接池设置为True
耗时:00:00:00.4972304
2.连接池设置为False
耗时:00:00:43.6183675
1 using System.Diagnostics;
2
3 using System.IO;
4
5
6 SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
7
8 builder.DataSource = "127.0.0.1";
9
10 builder.InitialCatalog = "database";
11
12 builder.UserID = "user";
13
14 builder.Password = "user";
15
16 builder.Pooling = true;
17
18 //builder.MaxPoolSize = 3;
19
20 //builder.MinPoolSize = 2;
21
22 SqlConnection con = new SqlConnection(builder.ConnectionString);
23
24 SqlCommand com = con.CreateCommand();
25
26
27 Stopwatch sw = new Stopwatch();
28
29 sw.Start();
30
31
32 for (int i = 1; i <= 10000; i++)
33
34 {
35
36 con.Open();
37
38 con.Close();
39
40 }
41
42
43 sw.Stop();
44
45 TimeSpan ts = sw.Elapsed;
46
47
48 string tie = ts.ToString();
49
50 StreamWriter swe = File.CreateText("test.txt");
51
52 swe.WriteLine(tie);
53
54 swe.Close();
55
相关文章推荐
- ado.net 连接池性能
- 使用ADO.NET2.0提升数据交互性能(3)
- ADO.NET性能优化方面的总结
- ADO.Net连接池--->附
- asp.net ADO.NET连接池使用与优化
- SQL Server 连接池 (ADO.NET)
- ODP.NET连接池性能计数器
- C#-ADO.Net连接池和连接字符串剖析
- ADO.NET 2.0技术内幕_连接池
- 6-16 ADO.NET基础和连接池
- ADO.NET2.0性能
- 关于ado.net连接池的一些分享(原文出自:http://www.cnblogs.com/rickie/archive/2004/10/02/48546.aspx)
- ADO.NET性能改善方法集合
- 再续NBear性能测试:ADO.NET, NBearV3, NHibernateV1, NBearLite, NBearLite+NBearMapping性能比较[2008/1/3修订:NBearLite更新至v1.0.1.0整合NBearMapping版地测试结果]
- 什么是连接池:Ado.net连接池使用总结:什么情况下需要禁用连接池?
- ADO.NET笔记——使用连接池
- Ado.net的连接池
- 关于ADO.Net连接池(Connection Pool)的一些个人见解
- C#-ADO.Net连接池和连接字符串剖析
- ADO.net,Linq to SQL和Entity Framework性能实测分析