扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
电脑型号:acer 4752g
成都创新互联公司专业为企业提供永济网站建设、永济做网站、永济网站设计、永济网站制作等企业网站建设、网页设计与制作、永济企业网站模板建站服务,10余年永济做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
电脑配置:
class Program
{
static void Main(string[] args)
{
Debug.Listeners.Add(new ConsoleTraceListener());
ShowExecuteTime("dataverylteBatch", () => DataVeryLiteInsertBatch());
ShowExecuteTime("dataverylte", () => DataVeryLiteInsert());
ShowExecuteTime("hibernate", () => HibernateInsert());
Console.WriteLine("完成");
Console.ReadKey();
}
public static void HibernateInsert()
{
// 读取配置
var config = new Configuration().Configure("Database.xml");
// 创建表结构
SchemaMetadataUpdater.QuoteTableAndColumns(config);
new SchemaExport(config).Create(false, true);
// 打开Session
var sessionFactory = config.BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
{
// 插入
for (int i = 0; i < 1000; i++)
{
var user = new User();
user.Name = "贼寇在何方"+i;
user.Password = "********";
user.Email = "realh4@gmail.com";
session.Save(user);
session.Flush();
Debug.WriteLine("Nhibernate now is inserted " + i);
}
}
}
public static void DataVeryLiteInsert()
{
for (int i = 0; i < 1000; i++)
{
var user = new VeryLiteUser();
user.Id = Guid.NewGuid().ToString();
user.Name = "贼寇在何方" + i;
user.Password = "********";
user.Email = "realh4@gmail.com";
user.Save(false);
Debug.WriteLine("DataVeryLite now is inserted " + i);
}
}
public static void DataVeryLiteInsertBatch()
{
Sqlite sqlite = new Sqlite();
var tran= sqlite.BeginTransaction();
var list = new List
for (int i = 0; i < 1000; i++)
{
var user = new VeryLiteUser();
user.Id = Guid.NewGuid().ToString();
user.Name = "贼寇在何方" + i;
user.Password = "********";
user.Email = "realh4@gmail.com";
list.Add(user);
Debug.WriteLine("VeryLiteUser now is add to list " + i);
}
sqlite.SaveOnly
tran.Commit();
}
public static void ShowExecuteTime(string name, Action action)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(name + " start,please wait.");
Debug.WriteLine(name + " start,please wait.");
int start = System.Environment.TickCount;
action();
int during = System.Environment.TickCount - start;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(name + ":During time is " + during / 1000.0 + " s");
Debug.WriteLine(name + ":During time is " + during / 1000.0 + " s");
Console.WriteLine();
}
插入条数:1000条
结果:
dataverylteBatch:用时2.59秒
dataverylte:用时156.64秒
hibernate:用时145.58秒
源代码(Demo)下载地址:http://files.cnblogs.com/shuqizhao/DataVeryLiteNHibernateSQLiteDemo.zip
DataVeryLite地址:http://dataverylite.codeplex.com/
欢迎吐槽!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流