I was a little worried if NHibernate would be too slow, so I did a few tests to see fast it was compared to writing the sql myself.
I was trying to insert a binary field, author and programID. When I did the sql manual it took 261ms to insert one row. When I inserted the row 10 times it took 344ms, and it took 526ms to insert the fields 100 times, When I did it with NHibernate I got the following times:
1 insert – 501ms
10 inserts – 873ms
100 inserts – 984ms
These times would vary quite a bit, but I think these is the apprx values.
The code to generate the NHIbernate looked like this:
Code:
public void PopulateData(int runs)
{
Configuration cfg = new Configuration();
cfg.AddAssembly("HibernateTest");
for (int i = 0; i < runs; i++)
{
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
FileStream fs = new FileStream(@"C:\maintest2.doc", FileMode.Open);
byte[] dataArray = new byte[fs.Length];
ReadData(fs, dataArray);
TestSpec testSpec = new TestSpec();
testSpec.CreationDate = DateTime.Now;
testSpec.Author = "Philip "+i;
testSpec.Description = dataArray;
fs.Close();
session.Save(testSpec);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
}
I just thought you guys might be interested in the results. So it looks like NHibernate is quite a bit slower, when you work with binary fields, than by doing it yourself.