Fluent NHibernate: Simple Many-to-Many Vs. Normal Many-to-Many Mapping Timing

Summary

In an earlier post I showed how to map a many-to-many relationship without using the HasManyToMany mapper. So I finally put together a simple test project (technically it’s two projects in one solution) to test the two methods side-by-side. To my surprise, it is very difficult to tell if one is faster than the other. One problem with speed testing involves caching. It’s difficult to know for sure how much of the results are cached in memory. I even used the GC.Collect() to clear any unused memory before performing each test.

Results

As you can see the results are not seriously conclusive. I reversed the ordering of the normal and easy methods and this is what I got:

Yeah, not conclusive. Bummer.

Technically, I should insert a thousand classes and then link them to each student. Then delete all students using both methods and see how it comes out. I suspect I’ll run into the same timing issues. The normal mapping method using ILists is quick because I have it set to LazyLoad. I guess that says something about using Fluent NHibernate for your ORM (the firstnames.txt file contains 1,219 lines that are inserted as student names for the insert test).

If anybody wants to take a shot at this, feel free to download the sample code and give it a try.

Download the sample code here:

FluentNHibernateSimpleVsNormal.zip

Leave a Reply