189 8069 5689

DataVeryLite和Nhibernate性能对比-创新互联

电脑型号:acer 4752g

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、荷塘网站维护、网站推广。

电脑配置:

DataVeryLite和Nhibernate性能对比


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(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/
欢迎吐槽!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:DataVeryLite和Nhibernate性能对比-创新互联
浏览路径:http://jkwzsj.com/article/ddejes.html

其他资讯