Nhibernate vs Entity Framework – a revised performance comparison

Note: before reading this article please see my views on comparing ORM tools. In short: this comparison is not suitable for comparing NHibernate and Entity Framework, due to the complexity of the tools vs the simplicity of this test; treat this post accordingly.

The reason I’m revising previous results is because some members of the NHibernate community looked into the code and discovered that the comparison wasn’t totally fair. While the test cases with Entity Framework used batch operations, the NHibernate implementation had this feature turned off. Tuna Toksoz was kind enough to re-write the critical parts of the code and apply settings enabling batching, you can download the revised source code here.

Note that I’ve made the source open for two reasons. First, I’d like the tests to be reproducible. And more importantly: I have experience with the two frameworks however I’m not an expert at any of them: therefore treat the results with caution. Anyone is free to analyze the source and if there are some issues in the code resulting in major performance drops, please let me know.

After Tuna modified the code NHibernate storage speed rocketed up compared to the previous version:

Framework/ No. of operations 1K 3K 8K 14 K 23K 33K 40K
NHibernate 1,22 3,25 8,98 13,11 28 38 46
Entity Framework 2,11 6,18 18,4 31,3 51,7 77 98


However improving performance does not stop here. Fabio Maulo posted a great article on why the original code was far from optimal and improved runtime results even more.


As I’ve stated before I don’t beleive there is a good way in comparing ORM frameworks and even if there were, this little test certanly is not it.

As the contribution of the NHibernate community members showed the more complex and configurable the tool, the more experience you’ll need to make the best of this. If you’re working on a performance critical product, you’d better know you’re tool well and use it accordingly.

But which one should I use?

From the current results it seems that there is no major performance difference between two tools and even if there is it might be due to misuse. So my advice is to use which ever tool suits you more based on its features.

At first glance Entity Framework seems to have a shorter learning curve as well as some nice integrated VS tools to make development easier. On the other hand there is a constantly active and helping NHibernate community always ready to answer questions and NHibernate seems to be much more customizable at a higher level. Also see this thread on EF vs NH features and learning as well to help decide.

The decision is up to you which one you find more suitable for your needs. However since both are proven and mature solutions you won’t be making a big mistake going with which either.

7 Responses to Nhibernate vs Entity Framework – a revised performance comparison
  1. John Rayner

    Thanks for posting the info. The link to download v2 of the code is broken, though. Any chance you could fix it up please?

  2. Gergely Orosz

    Thanks for noticing John. I’ve corrected the link, it should be working now.

  3. Alex Yakunin

    Greg, check out my comments to Fabio’s post.

  4. Paul

    Thanks for the post. While you say that your results aren’t conclusive, I think they’re enough that many folks *can* use them to say, “OK, performance isn’t a huge issue, let’s move on..” when making their choice.

    For my money, NHibernate is the better choice in most cases purely because it currently offers nearly perfect POCO development of my model, where EF requires that I couple to them right there in my domain model. Until EF fixes that, I’ll be shying away from them.

  5. Alex Yakunin

    Concerning “isn’t huge issue” – in many cases that’s really true. There are ORM frameworks working on PHP – and although they have zero chances to win @ ORMBattle, they still can be used in many cases.

  6. [...] Esta comparativa es del 2009 y ya han realizado una revisión de la misma, ya que los desarrolladores de... geeks.ms/blogs/adiazmartin/archive/2010/03/21/191-ef-vs-nhibernate-191-esa-es-la-pregunta.aspx