What kind of ORM framework do we need following the last ORM?
Compiled 11 ORM Framework test examples, with sample code and results, to easily understand the characteristics of various frameworks, pros and cons, ranked in no particular order
- Ef
- Pdf
- XCODE
- Crl
- NHibernate
- Mysoft
- Moon
- Cyq
- Dapper
- Ibatisnet
- Loognorm
Frame Style
- Fully object, with LINQ&LAMBDA syntax as the backing ef,crl,nhibernate
- Only result object, Cyq,dapper,ibatisnet,loognorm,pdf (pass condition as method parameter)
- Implement custom syntax Moon,mysoft,xcode using a proxy class (you need to generate a proxy class to construct your own query syntax)
There are many ways to implement the syntax, in detail you can see the test class call, convenience is also very different
In the frame above, the value can be passed as a parameter, but the programming and convenience will almost
Deployment Configuration
- Need to aid tool to generate model Moon,mysoft,pdf,xcode
- Need to define object mappings nhibernate,ibatisnet,ibatisnet It's a hassle to configure.
- Just write Model Ef,crl,cyq,dapper,loognorm
Open Data Connections
Some ORM only provide read data connection from config file, it is inconvenient to do (the latest version has no knowledge)
A ibatisnet,moon,pdf,xcode that cannot be implemented programmatically
Test purpose
- Test ORM Data Access performance, relatively simple brute, statistical object mapping conversion and return time, (pure-object ORM takes longer than an ORM in the form of parameters)
- ORM Development Call implementation, different ORM development style and ease of glance
Test results
- EF and NHibernate average down a little bit slower, other differences are small
- An ORM that implements a purely object-only operation can be more convenient.
- The need to manually map objects is more cumbersome to develop.
Test implementation
To demonstrate the ORM process, use objects as much as possible to represent
The various ORM properties may be implemented differently, so they are defined as interfaces
Entity interface
Public interface iproduct { int Id {get; set;} String ProductId {get; set;} String ProductName {get; set;} String BarCode {get; set;} DateTime addtime {get; set;} }
Test interface
Only the parameter index is defined here, and the corresponding object is created by index in the method.
Public interface Itester { iproduct getproduct (int index); String Remark {get;} BOOL Insert (int index); int Select (int index); int Update (int index); int Delete (int index); }
Interface implementation examples
To test ORM performance, try not to stitch SQL, which directly affects the results
public class Crltester:itester {public string Remark {get {Retu RN ""; }} public iproduct getproduct (int index) {return new Product () {Id = index, ProductName = "ProductName" + index, BarCode = "BarCode" + index, addtime = DateTime.Now}; } public bool Insert (int index) {var data = getproduct (index) as Product; PRODUCTMANAGE.INSTANCE.ADD (data); return true; } public int Select (int index) {var data = getproduct (index) as Product; var list = ProductManage.Instance.QueryList (b = = B.productname = = data. ProductName); Return list. Count; } public int Delete (int index) {var data = getproduct (index) as Product; var n = ProductManage.Instance.Delete (b = = b.ID = = data. ID); return n; } public int Update (int index) {var data = getproduct (index) as Product; Because it is not queried, manually set which properties have been changed by data. Change (b = b.productname); Data. Change (b = b.barcode); return ProductManage.Instance.Update (data); } }
test Procedure , call the interface implementation, to delete and change the loop to execute the specified number of times
static string Dotest (Itester tester, Testtype type,int N) {STOPW atch SW = new Stopwatch (); Insert SW. Start (); for (int i = 1, i <= N; i++) {switch (type) {case Testtyp E.delete:tester. Delete (i); Break Case TestType.INSERT:tester. Insert (i); Break Case TestType.SELECT:tester. Select (i); Break Case TestType.UPDATE:tester. Update (i); Break }} SW. Stop (); var times = SW. Elapsedmilliseconds; var avg = times/convert.todouble (n); return string. Format ("{0}, spents {1} milliseconds average {2}", type, SW. Elapsedmilliseconds, avg); }
Using the local database locally test, the results are as follows (for reference only)
EF 100-time start test 2015/4/13 16:28:48INSERT, spents 1459 milliseconds on average 14.59SELECT, spents 555 milliseconds on average 5.55UPDATE, spents 483 milliseconds on average 4.83DELETE, spents 178 milliseconds average 1.78===================================CRL starts test 100 times2015/4/13 16:28:54INSERT, spents 144 milliseconds on average 1.44SELECT, spents 190 milliseconds on average 1.9UPDATE, spents 81 milliseconds on average 0.81DELETE, spents 172 milliseconds average 1.72===================================PDF 100-time start Test2015/4/13 16:28:58INSERT, spents 173 milliseconds on average 1.73SELECT, spents 129 milliseconds on average 1.29UPDATE, spents 153 milliseconds on average 1.53DELETE, spents 51 milliseconds average 0.51===================================XCODE starts test 100 times2015/4/13 16:29:01INSERT, spents 432 milliseconds on average 4.32SELECT, spents 146 milliseconds on average 1.46UPDATE, spents 172 milliseconds on average 1.72DELETE, spents 123 milliseconds average 1.23===================================NHibernate to start testing 100 times2015/4/13 16:29:11INSERT, spents 317 milliseconds on average 3.17SELECT, spents 482 milliseconds on average 4.82UPDATE, spents 155 milliseconds on average 1.55DELETE, spents 178 milliseconds average 1.78===================================Mysoft to start testing 100 times2015/4/13 16:29:15INSERT, spents 374 milliseconds on average 3.74SELECT, spents 309 milliseconds on average 3.09UPDATE, spents 318 milliseconds on average 3.18DELETE, spents 247 milliseconds average 2.47===================================Moon to start testing 100 times2015/4/13 16:29:19INSERT, spents 185 milliseconds on average 1.85SELECT, spents 105 milliseconds on average 1.05UPDATE, spents 81 milliseconds on average 0.81DELETE, spents 127 milliseconds average 1.27===================================Cyq to start testing 100 times2015/4/13 16:29:24INSERT, spents 225 milliseconds on average 2.25SELECT, spents 131 milliseconds on average 1.31UPDATE, spents 63 milliseconds on average 0.63DELETE, spents 304 milliseconds average 3.04===================================Dapper to start testing 100 times2015/4/13 16:29:28INSERT, spents 141 milliseconds on average 1.41SELECT, spents 125 milliseconds on average 1.25UPDATE, spents 57 milliseconds on average 0.57DELETE, spents 80 milliseconds average 0.8===================================ibatisnet to start testing 100 times2015/4/13 16:29:32INSERT, spents 162 milliseconds on average 1.62SELECT, spents 111 milliseconds on average 1.11UPDATE, spents 60 milliseconds on average 0.6DELETE, spents 94 milliseconds average 0.94===================================Loognorm to start testing 100 times2015/4/13 16:29:37INSERT, spents 109 milliseconds on average 1.09SELECT, spents 94 milliseconds on average 0.94UPDATE, spents 96 milliseconds on average 0.96DELETE, spents 57 milliseconds average 0.57===================================
The EF insert behaves very slowly, possibly due to its mechanism
On top of that, the use of the ORM without parsing is relatively short, and the other is almost
Factors that affect efficiency
- Framework internal mechanisms, such as ef,insert-odd slow
- Object mapping and parsing time, object and table mapping transformations, query parsing
- Generated statement complexity and parameterization
Run
The above results are for reference only, the actual test results prevail, welcome message discussion
Test item: http://files.cnblogs.com/files/hubro/ORMTest.rar?a=2
Please change the data connection in config file, ibatisnet need to modify it separately
ORM Framework Sample and query test, first modified version (11 frames)