ADO.NET - 连接池性能

连接池性能测试
本文通过对比连接池开启与关闭的情况,进行了性能测试。结果显示,在进行大量数据库连接操作时,使用连接池可以显著提高效率,从43.6秒减少到0.497秒。

连接池性能测试代码如下:

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 

 

转载于:https://www.cnblogs.com/xuxiaoguang/archive/2008/08/12/1265807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值