in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Sqlite Entity Framework Insert Benchmark (it seems cost too much)

Last post 08-13-2008 12:35 PM by shunzimm. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 08-13-2008 12:01 PM

    Sqlite Entity Framework Insert Benchmark (it seems cost too much)

    In My Test ,Sqlite Entity Framework seems Cost too much (1976.8417 && 32.9986 ).

    tablename : Roles
    ddl:
    CREATE TABLE [Roles] (
        [RoleId] integer PRIMARY KEY NOT NULL,
        [RoleName] nvarchar (255) NOT NULL,
        [ApplicationName] nvarchar (255) NOT NULL
    );
    CREATE INDEX [IX_RoleName_ApplicationName] ON [Roles] ([RoleName], [ApplicationName]);

    providerEntities db = new providerEntities();

            for (int i = 1; i <= 2000; i++)
            {
                Role role = new Role();

                role.RoleName = txtRoleName.Text + i.ToString();

                role.ApplicationName = "TEST";

                db.AddToRoleSet(role);
            }

            long d1 = GetTickCount();

            db.SaveChanges();

            db.Connection.Close();

            long d2 = GetTickCount();

            Label1.Text = "edm add 2000 roles:";

            Label1.Text += (new TimeSpan(d2 - d1).TotalMilliseconds).ToString();

          /*  result is 1976.8417 in Milliseconds */

         SQLiteConnection conn = new SQLiteConnection("data source=|DataDirectory|test.db3");
            conn.Open();

            SQLiteTransaction tran = conn.BeginTransaction();
            SQLiteCommand cmd = new SQLiteCommand(conn); 

            for (int i = 2001; i <= 4000; i++)
            {
                cmd.CommandText = string.Format("insert into roles(rolename,applicationname) values('{0}','TEST')", txtRoleName.Text + i.ToString());

                //cmd.Parameters[0].Value = txtRoleName.Text + i.ToString();

                cmd.ExecuteNonQuery();
            }

            d1 = GetTickCount();

            tran.Commit();

            conn.Close();

            d2 = GetTickCount();

            Label1.Text += "sqlite add 2000 roles:";

            Label1.Text += (new TimeSpan(d2 - d1).TotalMilliseconds).ToString();

            Label1.Text += "<br />";

           /*  Result is 32.9986 in  Milliseconds*/

  • 08-13-2008 12:02 PM In reply to

    Re: Sqlite Entity Framework Insert Benchmark (it seems cost too much)

    GetTick Method:

    [DllImport("kernel32.dll")]
        static extern bool QueryPerformanceCounter([In, Out] ref long lpPerformanceCount);
        [DllImport("kernel32.dll")]
        static extern bool QueryPerformanceFrequency([In, Out] ref long lpFrequency);

        static long _f = 0;

        static public long GetTickCount()
        {
            long f = _f;

            if (f == 0)
            {
                if (QueryPerformanceFrequency(ref f))
                {
                    _f = f;
                }
                else
                {
                    _f = -1;
                }
            }
            if (f == -1)
            {
                return Environment.TickCount * 10000;
            }
            long c = 0;
            QueryPerformanceCounter(ref c);
            return (long)(((double)c) * 1000 * 10000 / ((double)f));
        }

        static long _tc = 0;

        static public DateTime GetExactNow()
        {
            if (_tc == 0)
            {
                long tc = GetTickCount();
                DateTime dt = DateTime.Now;
                _tc = dt.Ticks - tc;
                return dt;
            }

            return new DateTime(_tc + GetTickCount());
        }

  • 08-13-2008 12:11 PM In reply to

    Re: Sqlite Entity Framework Insert Benchmark (it seems cost too much)

    Run the test multiple times in a loop and time each loop.  There's some code that may be getting JIT'ted the first time this runs and could be skewing the numbers.

     

  • 08-13-2008 12:35 PM In reply to

    Re: Sqlite Entity Framework Insert Benchmark (it seems cost too much)

    Maybe this benchmark is just unfair.
    the SaveChanges method of  Entity Model ObjectContext will do the basic validation for each dirty entity before updating them,
    and then generate the updating sql for each of them,and then commit the changes. 

    ObjectContext  seems do more works in this.



Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems