From: Michael D. <mik...@us...> - 2004-05-26 15:48:00
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23016/NHibernate.Test Modified Files: PerformanceTest.cs Log Message: Changed test to generate the exact same sql with NHibernate and direct ADO.NET with IDbCommand & IDataReader. Index: PerformanceTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/PerformanceTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PerformanceTest.cs 25 May 2004 17:21:45 -0000 1.1 --- PerformanceTest.cs 26 May 2004 15:47:50 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Collections; using System.Data; *************** *** 23,27 **** /// <para> /// On a production machine, the finest level of detail you should log is WARN. On my machines ! /// test take 3 times the amount of time to run with a log level of DEBUG as WARN. /// </para> /// </remarks> --- 24,41 ---- /// <para> /// On a production machine, the finest level of detail you should log is WARN. On my machines ! /// test take about 3 times the amount of time to run with a log level of DEBUG compared to WARN. ! /// </para> ! /// <para> ! /// Currently (2004-05-26) NHibernate adds about 20% overhead versus a straight DataReader when ! /// the exact same sql is issued. NHibernate's DriverConnectionProvider has not implemented a ! /// Connection Cache or Prepared IDbCommand cache yet. No cache was configured for the class Simple for ! /// this test. So there are optimizations that are yet to be made, even then it is performing ! /// well compared to a DataReader. I plan on making a seperate csproj to store Performance ! /// Test because NProf has problems with getting performance figures from dlls running in NUnit - or ! /// atleast I have not been able to get it to work. ! /// </para> ! /// <para> ! /// Also test with a larger amount of data in the tables so they can be compared to a DataSet & Type DataSet ! /// will later be added. /// </para> /// </remarks> *************** *** 47,50 **** --- 61,65 ---- [Test] + //[Ignore("User should comment this out if they want it to run. Does not test any functions.")] public void Many() { *************** *** 54,58 **** long adonet = 0; ! for(int n = 0; n < 5; n++) { Simple[] simples = new Simple[n]; --- 69,74 ---- long adonet = 0; ! //for(int n = 0; n < 20; n++) ! for(int n = 0; n < 20; n++) { Simple[] simples = new Simple[n]; *************** *** 117,120 **** --- 133,137 ---- System.Console.Out.Write("NHibernate: " + hiber + "ms / Direct ADO.NET: " + adonet + "ms = Ratio: " + (((float)hiber/adonet)).ToString() ); + //cp.Close(); System.GC.Collect(); } *************** *** 138,153 **** } ! private void Hibernate(ISession s, Simple[] simples, object[] ids, int n, string runname) { ITransaction t = s.BeginTransaction(); ! for(int i = 0; i < n; i++) { s.Save(simples[i]); //, ids[i]); } ! for(int i = 0; i < n; i++) { ! simples[i].Name = "NH - A Different Name!" + i + n + runname; } --- 155,171 ---- } ! private void Hibernate(ISession s, Simple[] simples, object[] ids, int N, string runname) { ITransaction t = s.BeginTransaction(); ! for(int i = 0; i < N; i++) { s.Save(simples[i]); //, ids[i]); } + s.Flush(); ! for(int i = 0; i < N; i++) { ! simples[i].Name = "NH - " + i + N + runname + " - " + System.DateTime.Now.Ticks; } *************** *** 158,164 **** // hql is throwing perf way off... //Assert.IsTrue( s.Delete("from s in class NHibernate.DomainModel.Simple") == n); ! for(int i = 0; i < n; i++) { ! s.Delete(simples[i]); } s.Flush(); --- 176,185 ---- // hql is throwing perf way off... //Assert.IsTrue( s.Delete("from s in class NHibernate.DomainModel.Simple") == n); ! ! IList simpleList = s.CreateCriteria(typeof(Simple)).List(); ! ! for(int i = 0; i < simpleList.Count; i++) { ! s.Delete((Simple)simpleList[i]); } s.Flush(); *************** *** 167,171 **** } ! private void DirectAdoNet(IDbConnection c, Simple[] simples, object[] ids, int n, string runname) { IDbCommand insert = InsertCommand(); --- 188,192 ---- } ! private void DirectAdoNet(IDbConnection c, Simple[] simples, object[] ids, int N, string runname) { IDbCommand insert = InsertCommand(); *************** *** 191,195 **** update.Prepare(); ! for(int i = 0; i < n; i++) { ((IDbDataParameter)insert.Parameters[0]).Value = simples[i].Name; --- 212,216 ---- update.Prepare(); ! for(int i = 0; i < N; i++) { ((IDbDataParameter)insert.Parameters[0]).Value = simples[i].Name; *************** *** 203,209 **** } ! for(int i = 0; i < n; i++) { ! ((IDbDataParameter)update.Parameters[0]).Value = "DR - A Different Name!" + i + n + runname; ((IDbDataParameter)update.Parameters[1]).Value = simples[i].Address; ((IDbDataParameter)update.Parameters[2]).Value = simples[i].Count; --- 224,230 ---- } ! 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; *************** *** 216,221 **** IDataReader reader = select.ExecuteReader(); ! long[] keys = new long[n]; ! Simple[] simplesFromReader = new Simple[n]; int j = 0; --- 237,242 ---- IDataReader reader = select.ExecuteReader(); ! long[] keys = new long[N]; ! Simple[] simplesFromReader = new Simple[N]; int j = 0; *************** *** 225,230 **** { //SELECT s.id_, s.name, s.address, s.count_, s.date_, s.other - simplesFromReader[j] = new Simple(); keys[j] = (long)reader[0]; simplesFromReader[j].Key = keys[j]; simplesFromReader[j].Name = (string)reader[1]; --- 246,251 ---- { //SELECT s.id_, s.name, s.address, s.count_, s.date_, s.other keys[j] = (long)reader[0]; + simplesFromReader[j] = new Simple(); simplesFromReader[j].Key = keys[j]; simplesFromReader[j].Name = (string)reader[1]; *************** *** 243,247 **** reader.Close(); ! for(int i = 0; i < n; i++) { ((IDbDataParameter)delete.Parameters[0]).Value = (long)keys[i]; --- 264,268 ---- reader.Close(); ! for(int i = 0; i < N; i++) { ((IDbDataParameter)delete.Parameters[0]).Value = (long)keys[i]; |