DataVeryLite和Nhibernate性能对比_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > DataVeryLite和Nhibernate性能对比

DataVeryLite和Nhibernate性能对比

 2013/11/25 15:29:06  怡盛  博客园  我要评论(0)
  • 摘要:电脑型号:acer4752g电脑配置:代码分享:1classProgram2{3staticvoidMain(string[]args)4{5Debug.Listeners.Add(newConsoleTraceListener());6ShowExecuteTime("dataverylteBatch",()=>DataVeryLiteInsertBatch());78ShowExecuteTime("dataverylte",()=>DataVeryLiteInsert())
  • 标签:hibernate

电脑型号:acer 4752g

电脑配置:

代码分享:

 

 1  class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             Debug.Listeners.Add(new ConsoleTraceListener());
 6             ShowExecuteTime("dataverylteBatch", () => DataVeryLiteInsertBatch());
 7 
 8             ShowExecuteTime("dataverylte", () => DataVeryLiteInsert());
 9             ShowExecuteTime("hibernate", () => HibernateInsert());
10             Console.WriteLine("完成");
11             Console.ReadKey();
12         }
13 
14         public static void HibernateInsert()
15         {
16             // 读取配置
17             var config = new Configuration().Configure("Database.xml");
18 
19             // 创建表结构
20             SchemaMetadataUpdater.QuoteTableAndColumns(config);
21             new SchemaExport(config).Create(false, true);
22 
23             // 打开Session
24             var sessionFactory = config.BuildSessionFactory();
25             using (var session = sessionFactory.OpenSession())
26             {
27                 // 插入
28                 for (int i = 0; i < 1000; i++)
29                 {
30                     var user = new User();
31                     user.Name = "贼寇在何方"+i;
32                     user.Password = "********";
33                     user.Email = "realh3@gmail.com";
34 
35                     session.Save(user);
36                     session.Flush();
37                     Debug.WriteLine("Nhibernate now is inserted " + i);
38                 }
39             }
40         }
41 
42         public static void DataVeryLiteInsert()
43         {
44             for (int i = 0; i < 1000; i++)
45             {
46                 var user = new VeryLiteUser();
47                 user.Id = Guid.NewGuid().ToString();
48                 user.Name = "贼寇在何方" + i;
49                 user.Password = "********";
50                 user.Email = "realh3@gmail.com";
51                 user.Save(false);
52                 Debug.WriteLine("DataVeryLite now is inserted " + i);
53             }
54         }
55         public static void DataVeryLiteInsertBatch()
56         {
57             Sqlite sqlite = new Sqlite();
58             var tran= sqlite.BeginTransaction();
59             var list = new  List<VeryLiteUser>();
60             for (int i = 0; i < 1000; i++)
61             {
62                 var user = new VeryLiteUser();
63                 user.Id = Guid.NewGuid().ToString();
64                 user.Name = "贼寇在何方" + i;
65                 user.Password = "********";
66                 user.Email = "realh3@gmail.com";
67                 list.Add(user);
68                 Debug.WriteLine("VeryLiteUser now is add to list " + i);
69             }
70             sqlite.SaveOnly<VeryLiteUser>(list, false, tran);
71             tran.Commit();
72         }
73 
74         public static void ShowExecuteTime(string name, Action action)
75         {
76             Console.ForegroundColor = ConsoleColor.Yellow;
77             Console.WriteLine(name + " start,please wait.");
78             Debug.WriteLine(name + " start,please wait.");
79             int start = System.Environment.TickCount;
80             action();
81             int during = System.Environment.TickCount - start;
82             Console.ForegroundColor = ConsoleColor.Red;
83             Console.WriteLine(name + ":During time is " + during / 1000.0 + " s");
84             Debug.WriteLine(name + ":During time is " + during / 1000.0 + " s");
85             Console.WriteLine();
86         }

插入条数:1000条

结果:

dataverylteBatch:用时2.59秒
dataverylte:用时156.64秒
hibernate:用时145.58秒

源代码(Demo)下载地址:http://files.cnblogs.com/shuqizhao/DataVeryLiteNHibernateSQLiteDemo.zip
DataVeryLite地址:http://dataverylite.codeplex.com/
欢迎吐槽!


 
 
发表评论
用户名: 匿名