ADO.NET - 连接池性能
连接池性能测试代码如下:
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
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