Firebire嵌入式插入数据
Firebird嵌入式模式插入数据速度不慢,应该说是远远高于Firebird的Super Server和MSSQL Express 2005
在未采取事务的情况下,embedded略胜default;
采用事务情况下,轻量级数据库表结构embedded完胜default,重量级数据库表结构embedded略胜default;
| 共插入2列 | ||
| embedded | default | |
| 1条 | 0.0249072 | 0.0463833 |
| 0.0251514 | 0.0228012 | |
| 1000条 | 1.8725891 | 2.1519435 |
| 1.4473543 | 2.0056906 | |
| 1.5341267 | 2.2021085 | |
| 10000条 | 18.1739906 | 24.9880711 |
| 15.2675116 | 22.4957712 | |
| 18.0908583 | 19.5486584 | |
| 100000条 | 3m 28.4s | 4m 49.5s |
| 1000000条(事务) | 19.0361329 | 2m 49.9s |
| 共插入98列 | ||
| embedded | default | |
| 1000000条(事务) | 3m 29.07s | 3m 46.02s |
1 public static string ConnectString(string fileName)
2 {
3 FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
4 cs.DataSource = "localhost";
5 cs.Database = fileName;
6 cs.ServerType = FbServerType.Embedded;
7 cs.UserID = "sysdba";
8 cs.Password = "masterkey";
9 cs.Dialect = 3;
10 cs.ClientLibrary = @"F:\firebird\fbembed.dll";
11 return cs.ToString();
12 }
13
14 private void button1_Click(object sender, EventArgs e)
15 {
16 FbConnection cn = new FbConnection();
17 cn.ConnectionString = ConnectString(@"d:\data\test.fdb");
18 Stopwatch sw = new Stopwatch();
19 FbCommand cm = new FbCommand("insert into NEW_TABLE values ('firebird','embedded')", cn);
20 try
21 {
22 cn.Open();
23 sw.Start();
24 for (int i = 0; i < 1000000; i++)
25 {
26 cm.ExecuteNonQuery();
27 }
28 sw.Stop();
29 MessageBox.Show(sw.Elapsed.ToString());
30 }
31 catch (FbException ex)
32 {
33 MessageBox.Show(ex.Message);
34 }
35 finally
36 {
37 cn.Close();
38 }
39 }
2 {
3 FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
4 cs.DataSource = "localhost";
5 cs.Database = fileName;
6 cs.ServerType = FbServerType.Embedded;
7 cs.UserID = "sysdba";
8 cs.Password = "masterkey";
9 cs.Dialect = 3;
10 cs.ClientLibrary = @"F:\firebird\fbembed.dll";
11 return cs.ToString();
12 }
13
14 private void button1_Click(object sender, EventArgs e)
15 {
16 FbConnection cn = new FbConnection();
17 cn.ConnectionString = ConnectString(@"d:\data\test.fdb");
18 Stopwatch sw = new Stopwatch();
19 FbCommand cm = new FbCommand("insert into NEW_TABLE values ('firebird','embedded')", cn);
20 try
21 {
22 cn.Open();
23 sw.Start();
24 for (int i = 0; i < 1000000; i++)
25 {
26 cm.ExecuteNonQuery();
27 }
28 sw.Stop();
29 MessageBox.Show(sw.Elapsed.ToString());
30 }
31 catch (FbException ex)
32 {
33 MessageBox.Show(ex.Message);
34 }
35 finally
36 {
37 cn.Close();
38 }
39 }
浙公网安备 33010602011771号