public void IbatisOnly() { for (int n = 2; n < 4000; n *= 2) { Simple[] simples = new Simple[n]; object[] ids = new object[n]; for (int i = 0; i < n; i++) { simples[i] = new Simple(); simples[i].Init(); simples[i].Count = i; simples[i].Id = i; } //Now do timings Stopwatch stopWatch = new Stopwatch(); GC.Collect(); GC.WaitForPendingFinalizers(); ISession session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h1"); stopWatch.Stop(); double ibatis = 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h2"); stopWatch.Stop(); ibatis += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h2"); stopWatch.Stop(); ibatis += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); System.Console.WriteLine("Objects: " + n + " - iBATIS DataMapper: " + ibatis.ToString("F3")); } System.GC.Collect(); }
private void Ibatis(ISession session, Simple[] simples, int N, string runname) { using (ITransaction transaction = session.BeginTransaction()) { for (int i = 0; i < N; i++) { dataMapper.Insert("InsertSimple", simples[i]); } for (int i = 0; i < N; i++) { simples[i].Name = "NH - " + i + N + runname + " - " + System.DateTime.Now.Ticks; dataMapper.Update("UpdateSimple", simples[i]); } for (int i = 0; i < N; i++) { dataMapper.Delete("DeleteSimple", simples[i].Id); } transaction.Complete(); } }
public void Simultaneous() { double ibatis = 0; double adonet = 0; IDbConnection connection = sessionFactory.DataSource.DbProvider.CreateConnection(); connection.ConnectionString = sessionFactory.DataSource.ConnectionString; for (int n = 2; n < 4000; n *= 2) { Simple[] simples = new Simple[n]; for (int i = 0; i < n; i++) { simples[i] = new Simple(); simples[i].Init(); simples[i].Count = i; simples[i].Id = i; } ISession session = sessionFactory.OpenSession(); Ibatis(session, simples, n, "h0"); session.Close(); connection.Open(); DirectAdoNet(connection, simples, n, "j0"); connection.Close(); session = sessionFactory.OpenSession(); Ibatis(session, simples, n, "h0"); session.Close(); connection.Open(); DirectAdoNet(connection, simples, n, "j0"); connection.Close(); //Now do timings Stopwatch stopWatch = new Stopwatch(); GC.Collect(); GC.WaitForPendingFinalizers(); session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h1"); stopWatch.Stop(); ibatis = 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); connection.Open(); stopWatch.Start(); DirectAdoNet(connection, simples, n, "j1"); stopWatch.Stop(); adonet = 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); connection.Close(); session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h2"); stopWatch.Stop(); ibatis += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); connection.Open(); stopWatch.Start(); DirectAdoNet(connection, simples, n, "j2"); stopWatch.Stop(); adonet += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); connection.Close(); session = sessionFactory.OpenSession(); stopWatch.Start(); Ibatis(session, simples, n, "h2"); stopWatch.Stop(); ibatis += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); session.Close(); connection.Open(); stopWatch.Start(); DirectAdoNet(connection, simples, n, "j2"); stopWatch.Stop(); adonet += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); connection.Close(); System.Console.Out.WriteLine("Objects " + n + " iBATIS DataMapper : " + ibatis.ToString("F3") + " / Direct ADO.NET: " + adonet.ToString("F3") + " Ratio: " + ((ibatis / adonet)).ToString("F3")); } System.GC.Collect(); }
public void Many() { double ibatis = 0; double adonet = 0; for (int n = 0; n < 5; n++) { Simple[] simples = new Simple[n]; for (int i = 0; i < n; i++) { simples[i] = new Simple(); simples[i].Init(); simples[i].Count = i; simples[i].Id = i; } ISession session = sessionFactory.OpenSession(); Ibatis(session, simples, n, "h0"); session.Close(); IDbConnection connection = sessionFactory.DataSource.DbProvider.CreateConnection(); connection.ConnectionString = sessionFactory.DataSource.ConnectionString; connection.Open(); DirectAdoNet(connection, simples, n, "j0"); connection.Close(); session = sessionFactory.OpenSession(); Ibatis(session, simples, n, "h0"); session.Close(); connection.Open(); DirectAdoNet(connection, simples, n, "j0"); connection.Close(); // now do timings int loops = 30; Stopwatch stopWatch = new Stopwatch(); for (int runIndex = 1; runIndex < 4; runIndex++) { GC.Collect(); GC.WaitForPendingFinalizers(); stopWatch.Start(); for (int i = 0; i < loops; i++) { session = sessionFactory.OpenSession(); Ibatis(session, simples, n, "h" + runIndex.ToString()); session.Close(); } stopWatch.Stop(); ibatis += 1000000 * (stopWatch.ElapsedMilliseconds / (double)loops); GC.Collect(); GC.WaitForPendingFinalizers(); stopWatch.Start(); for (int i = 0; i < loops; i++) { connection.Open(); DirectAdoNet(connection, simples, n, "j" + runIndex.ToString()); connection.Close(); } stopWatch.Stop(); adonet += 1000000 * (stopWatch.ElapsedMilliseconds / (double)loops); } } System.Console.Out.WriteLine("iBatis DataMapper : " + ibatis.ToString("F3") + " / Direct ADO.NET: " + adonet.ToString("F3") + " Ratio: " + ((ibatis / adonet)).ToString("F3")); System.GC.Collect(); }
private void DirectAdoNet(IDbConnection c, Simple[] simples, int N, string runname) { IDbCommand insert = InsertCommand(); IDbCommand delete = DeleteCommand(); IDbCommand select = SelectCommand(); IDbCommand update = UpdateCommand(); IDbTransaction t = c.BeginTransaction(); insert.Connection = c; delete.Connection = c; select.Connection = c; update.Connection = c; insert.Transaction = t; delete.Transaction = t; select.Transaction = t; update.Transaction = t; insert.Prepare(); delete.Prepare(); select.Prepare(); update.Prepare(); for (int i = 0; i < N; i++) { ((IDbDataParameter)insert.Parameters[0]).Value = simples[i].Name; ((IDbDataParameter)insert.Parameters[1]).Value = simples[i].Address; ((IDbDataParameter)insert.Parameters[2]).Value = simples[i].Count; ((IDbDataParameter)insert.Parameters[3]).Value = simples[i].Date; ((IDbDataParameter)insert.Parameters[4]).Value = simples[i].Pay; ((IDbDataParameter)insert.Parameters[5]).Value = simples[i].Id; insert.ExecuteNonQuery(); } for (int i = 0; i < N; i++) { ((IDbDataParameter)update.Parameters[0]).Value = "DR - " + i + N + runname + " - " + System.DateTime.Now.Ticks; ((IDbDataParameter)update.Parameters[1]).Value = simples[i].Address; ((IDbDataParameter)update.Parameters[2]).Value = simples[i].Count; ((IDbDataParameter)update.Parameters[3]).Value = simples[i].Date; ((IDbDataParameter)update.Parameters[4]).Value = simples[i].Pay; ((IDbDataParameter)update.Parameters[5]).Value = simples[i].Id; update.ExecuteNonQuery(); } for (int i = 0; i < N; i++) { ((IDbDataParameter)delete.Parameters[0]).Value = simples[i].Id; delete.ExecuteNonQuery(); } t.Commit(); }
public void AdoNetOnly() { for (int n = 2; n < 4000; n *= 2) { Simple[] simples = new Simple[n]; for (int i = 0; i < n; i++) { simples[i] = new Simple(); simples[i].Init(); simples[i].Count = i; simples[i].Id = i; } //Now do timings Stopwatch stopWatch = new Stopwatch(); IDbConnection _connection = sessionFactory.DataSource.DbProvider.CreateConnection(); _connection.ConnectionString = sessionFactory.DataSource.ConnectionString; _connection.Open(); stopWatch.Start(); DirectAdoNet(_connection, simples, n, "j1"); stopWatch.Stop(); double adonet = 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); _connection.Close(); _connection.Open(); stopWatch.Start(); DirectAdoNet(_connection, simples, n, "j2"); stopWatch.Stop(); adonet += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); _connection.Close(); _connection.Open(); stopWatch.Start(); DirectAdoNet(_connection, simples, n, "j2"); stopWatch.Stop(); adonet += 1000000 * (stopWatch.ElapsedMilliseconds / (double)n); _connection.Close(); System.Console.Out.WriteLine("Objects: " + n + " Direct ADO.NET: " + adonet.ToString("F3")); } System.GC.Collect(); }