您好,登錄后才能下訂單哦!
電腦型號: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");
// 創(chuàng)建表結構
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();
}
插入條數(shù):1000條
結果:
dataverylteBatch:用時2.59秒
dataverylte:用時156.64秒
hibernate:用時145.58秒
源代碼(Demo)下載地址:http://files.cnblogs.com/shuqizhao/DataVeryLiteNHibernateSQLiteDemo.zip
DataVeryLite地址:http://dataverylite.codeplex.com/
歡迎吐槽!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。