电脑型号:acer 4752g
电脑配置:
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<VeryLiteUser>();
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<VeryLiteUser>(list, false, tran);
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/
欢迎吐槽!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。