3

In short, what works faster:

  • SessionFactory precompiling XML configuration, or
  • Fluent NHibernate providing configuration programmatically ?
alex
  • 74,215
  • 9
  • 49
  • 57
  • Why do you care about the difference? It should be a small fraction of a second, or takes it longer in your case? – Paco Oct 26 '09 at 19:47
  • Just didn't know how Fluent NHibernate works, thought that it could be more efficient than parcing XML configuration. – alex Oct 26 '09 at 20:08

2 Answers2

8

My personal experience has been that the building of the Configuration object (which is unavoidable* regardless of whether Fluent is used) generally dwarfs the time required to setup a FluentConfiguration object, with the factor increasing as the number of mappings increase.

On a 2.5 Ghz c2d, with my project with approximately 15 mappings, it took 360ms for FluentConfiguration, and 5215ms for Configuration.

On a test project with 1000 mappings (simple classes with 2-3 string properties), it took 470ms for FluentConfiguration, and 40336 (40 seconds!) for Configuration.

*Actually, not really. most of the cost of Configuration comes from validating the XML mappings. Ayende has discussed it here (as well as a quick speedup obtained from merging the mappings into a single file), and a possible alternative to building the configuration at application startup is to serialize it as discussed here. In the 1000-mapping test project, this reduced the time required to get a Configuration object to around 30ms (although it has also increased the time required to build the SessionFactory from ~3 to ~4 seconds - I am unsure why).

viggity
  • 15,039
  • 7
  • 88
  • 96
fostandy
  • 4,282
  • 4
  • 37
  • 41
3

Fluent NHIbernate creates the XML documents and Sessionfactory under the hood, so it is slower than not using Fluent NHibernate.

Why do you ask?

Paco
  • 8,335
  • 3
  • 30
  • 41
  • I didn't know that Fluent NHibernate creates XML document, I though it maybe using some internal API to generate prcompiled mapping. – alex Oct 26 '09 at 18:39