NHibernate vs Entity Framework: a performance test(zhuan)

 

As part of my thesis I measured the performance of some .NET ORM frameworks including NHibernate and Entity Framework. Measuring was done by implementing two simple applications using the same table structure and doing the same operations on the same data.

Note: before reading this article please see my views on comparing ORM tools. Also see the follow up post to this comparison for revised results.

I measured the time it took for each framework to complete these operations:

  • store
  • read over relations
  • read by ID
  • update
  • delete

The results were somewhat interesting. Here is a short summary of what I’ve found out.

Operation \ Number of operationsNHiberante - 4KEntity Framework - 4KNHiberante - 40KEntity Framework- 40KWinner
Store37,379,19150098Entity Framework
Read over relations1,010,5410,134,18Entity Framework
Read by ID3,0625,22246230NHibernate with smaller amount of objects
Update6,617,347772Both
Delete3,3516,76581824NHibernate

Read on if you’re interested in the details of the performance measurements.

Update: the source code of the program used to measure is nowavailable for download.

How performance was measured

The data model I’ve set up to measure with was pretty simple. I used three entites: a Company entity which had multiple Employees all of which had multiple Reports all with a 1-n relation.

The detailed results for each operation are as follow (note that the graphs use logarithmic scale):

 

Storage

 

Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate4,9520,64112280575110715000
Entity Framework2,116,1818,431,351,77798

storage3

Update (2009. 08. 24.):
After NHibernate improvements by Tuna Toksoz (download source) this metric changed the following way:

Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate1,223,258,9813,11283846
Entity Framework2,116,1818,431,351,77798

store2

Read over relations
Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate0,210,661,813,315,08,2410,13
Entity Framework0,170,40,961,762,473,914,18

read

Read by ID
Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate0,281,3113,037,680175,5246
Entity Framework5,5617,034883132195230

readbyid

Update
Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate1,744,5417,133,243,476877
Entity Framework1,995,2914,224,241,95972

update

Delete
Framework/ No. of operations1K3K8K14 K23K33K40K
NHibernate0,782,318,8320,6284658
Entity Framework1,788,1952,213332010141895

delete

Conclusion

The performance measurements only provided significant differences in two cases.

  • When it comes to storing data, Entity Framework proved to be significantly faster than NHibernate
  • When deleting data, NHibernate was much faster than Entity Framework

My conclusion however after the test was that in those scenarios when the number of the operations is not too high performance does not differentiate that much. I would choose between these two tools based on which ones provides faster, more efficient and more straightforward development with the current project.

Give me the code

As many of the commenters pointed out a comparison is not really valid without publishing the code enabling validation of this measurement. The program I’ve written to do the test can therefore be downloaded:NHibernate vs Entity Framework source code.

To set up and run the project after downloading an unzipping the package follow these steps:

  • Create two MSSQL Databases (e.g. EntityFrameworkTest and NHibernateTest)
  • Run CreateTables.sql on both databases to create the database structure
  • In the App.config section of the MeasurementController project set the connection strings for NHibernate and Entity Framework (replace the !!! marks)
  • Build the solution
  • Run the MeasurementController project
  • Run times are written to the output and also saved in files in the bin/Data folder

Some additional comments for understanding the source:

  • Upon every run test data is created in an XML file. From this XML file Company, Emlpoyee and Report objects are created in-memory as the test structure
  • This test structure is passed to the NHibernate and Entity Framework implementations of the Store, Read, Read by ID, Update and Delete tests (in the source additionally search is also measured) on each test run.

转载于:https://www.cnblogs.com/pursue/archive/2009/09/22/1571485.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值