.NET 之 ORM 性能评测
程序员文章站
2022-06-19 17:14:11
.NET 之 ORM 性能评测 Why 1. 你应该总能听到某ORM性能比Dapper高 2. 你应该有如下疑问: 1. 基准测试是否权威 2. 基准测试的方式是否合理 3. 基准测试的标准是否能够统一 4. 统一基准测试标准/规范 如何进行姿势正确的性能测试 相信大家对 Dapper 的性能,以及 ......
.net 之 orm 性能评测
why
- 你应该总能听到某orm性能比dapper高
- 你应该有如下疑问:
- 基准测试是否权威
- 基准测试的方式是否合理
- 基准测试的标准是否能够统一
- 统一基准测试标准/规范
如何进行姿势正确的性能测试
相信大家对 dapper 的性能,以及基准测试的权威性是没有疑问的(否则不会有那么多orm在做性能测试的时候直接选型dapper),那么我们就使用 dapper 性能基准测试 来作为我们的基准测试模板,并加入一些没有纳入基准测试的 orm 。这样从合理性/可信度就大体有了一个标准和保障。
接下来 fork dapper github 仓库,并添加了 smartsql/ibatis.net/freesql/sqlsugar/chloe
源代码地址:https://github.com/ahoo-wang/dapper,如对测试结果,测试方法有疑问请给我提交issue。
如何自己进行以上基准测试
强烈建议读者按照以下步骤自己运行基准测试。
- git-clone https://github.com/ahoo-wang/dapper
- cd dapper/dapper.tests.performance
- dotnet publish -c release
- 运行 dapper.tests.performance.exe
- 提示输入,请输入 "*" 运行所有基准测试
- 等待测试结果,目录:benchmarkdotnet.artifacts 下会有一个日志文件,和 results 文件夹 (测试结果文件存放在此目录)
基准测试结果
重要提示:freesql/sqlsugar 官方nuget包为非release版本,所以测试结果会有影响,仅供参考。
benchmarkdotnet=v0.11.1, os=windows 10.0.17763 intel core i7-8750h cpu 2.20ghz (max: 2.21ghz) (coffee lake), 1 cpu, 12 logical and 6 physical cores [host] : .net framework 4.7.2 (clr 4.0.30319.42000), 64bit ryujit-v4.8.3801.0 shortrun : .net framework 4.7.2 (clr 4.0.30319.42000), 64bit ryujit-v4.8.3801.0
orm | method | return | mean | rank | gen 0 | gen 1 | gen 2 | allocated |
---|---|---|---|---|---|---|---|---|
belgrade | executereader | post | 78.74 us | 1 | 2.2500 | 0.6250 | - | 10.63 kb |
linq to db | 'first (compiled)' | post | 97.61 us | 2 | 0.5000 | - | - | 2.67 kb |
linq to db | query<t> | post | 103.05 us | 3 | 1.3750 | 0.1250 | - | 6.91 kb |
hand coded | sqlcommand | post | 107.37 us | 4 | 2.0000 | 1.0000 | 0.5000 | 12.29 kb |
dapper | queryfirstordefault<dynamic> | dynamic | 110.83 us | 5 | 2.8750 | 0.1250 | - | 13.57 kb |
dapper | queryfirstordefault<t> | post | 111.65 us | 5 | 2.2500 | 1.0000 | 0.3750 | 13.53 kb |
hand coded | datatable | dynamic | 114.78 us | 6 | 2.0000 | 0.5000 | - | 12.51 kb |
petapoco | 'fetch<t> (fast)' | post | 114.95 us | 6 | 2.2500 | 0.8750 | 0.2500 | 13.71 kb |
dapper | 'query<dynamic> (buffered)' | dynamic | 115.54 us | 6 | 2.2500 | 1.0000 | 0.2500 | 13.93 kb |
petapoco | fetch<t> | post | 119.76 us | 7 | 2.5000 | 1.0000 | 0.2500 | 14.66 kb |
dapper | 'query<t> (buffered)' | post | 122.10 us | 8 | 2.2500 | 0.8750 | 0.3750 | 13.86 kb |
susanoo | 'execut<dynamic> (static)' | dynamic | 122.68 us | 8 | 2.5000 | 0.7500 | 0.2500 | 15.03 kb |
massive | 'query (dynamic)' | dynamic | 122.82 us | 8 | 2.3750 | 0.8750 | 0.2500 | 14.25 kb |
servicestack | singlebyid<t> | post | 123.93 us | 8 | 3.0000 | 0.7500 | 0.2500 | 17.59 kb |
linq to db | first | post | 124.53 us | 8 | 1.1250 | 0.1250 | - | 5.53 kb |
smartsql | querysinglesqlparametercollection | post | 125.26 us | 8 | 2.5000 | 0.7500 | 0.2500 | 15.48 kb |
smartsql | querysingle | post | 126.79 us | 9 | 2.5000 | 0.7500 | 0.2500 | 15.59 kb |
linq to sql | 'first (compiled)' | post | 127.17 us | 9 | 2.0000 | - | - | 9.87 kb |
smartsql | getbyid | post | 127.24 us | 9 | 2.7500 | 0.7500 | 0.2500 | 15.89 kb |
smartsql | querysinglestrongrequest | post | 127.70 us | 9 | 2.5000 | 0.7500 | 0.2500 | 15.51 kb |
smartsql | querysinglefromxml | post | 128.27 us | 9 | 2.7500 | 0.7500 | 0.2500 | 16.23 kb |
susanoo | 'execute<t> (static)' | post | 128.92 us | 9 | 2.5000 | 0.7500 | 0.2500 | 15.05 kb |
smartsql | querysinglestrongrequest<dynamic> | dynamic | 129.88 us | 9 | 2.7500 | 1.0000 | 0.5000 | 16.54 kb |
smartsql | querysinglesqlparametercollection<dynamic> | dynamic | 130.96 us | 9 | 2.5000 | 0.7500 | 0.2500 | 16.51 kb |
dapper | 'contrib get<t>' | post | 132.10 us | 9 | 2.2500 | 1.0000 | 0.2500 | 14.51 kb |
devexpress.xpo | findobject<t> | post | 137.14 us | 10 | 6.5000 | 0.2500 | - | 29.97 kb |
susanoo | 'execute<dynamic> (cache)' | dynamic | 140.24 us | 11 | 3.2500 | 1.0000 | 0.5000 | 20.48 kb |
susanoo | 'execute<t> (cache)' | post | 141.23 us | 11 | 3.2500 | 0.7500 | 0.2500 | 20.96 kb |
ef 6 | sqlquery | post | 154.68 us | 12 | 4.7500 | 0.7500 | - | 27.96 kb |
devexpress.xpo | getobjectbykey<t> | post | 160.87 us | 13 | 5.2500 | 1.2500 | - | 32.35 kb |
ibatis | queryforobject | post | 163.87 us | 14 | 2.7500 | 0.7500 | 0.2500 | 16.59 kb |
dapper | 'query<t> (unbuffered)' | post | 166.28 us | 15 | 2.2500 | 0.7500 | 0.2500 | 13.89 kb |
dapper | 'query<dynamic> (unbuffered)' | dynamic | 171.82 us | 16 | 2.2500 | 0.7500 | 0.2500 | 13.93 kb |
devexpress.xpo | query<t> | post | 172.38 us | 16 | 7.5000 | 0.2500 | - | 35.02 kb |
freesql | fromsqlfirstdynamic | dynamic | 180.44 us | 17 | 3.2500 | 0.7500 | 0.2500 | 19.38 kb |
ef core | 'first (compiled)' | post | 188.02 us | 18 | 3.5000 | - | - | 16.14 kb |
freesql | fromsqlfirst | post | 196.92 us | 19 | 3.2500 | 0.7500 | 0.2500 | 19.17 kb |
nhibernate | get<t> | post | 201.46 us | 20 | 5.7500 | 0.7500 | - | 32.62 kb |
nhibernate | hql | post | 207.57 us | 21 | 5.5000 | 0.7500 | - | 35.11 kb |
chloe | first | post | 209.26 us | 21 | 5.0000 | 0.7500 | 0.2500 | 29.85 kb |
ef core | sqlquery | post | 234.51 us | 22 | 4.0000 | - | - | 20.64 kb |
ef core | first | post | 238.67 us | 23 | 4.2500 | - | - | 20.33 kb |
ef 6 | first | post | 243.86 us | 24 | 10.5000 | - | - | 48.44 kb |
linq to sql | executequery | post | 250.54 us | 25 | 7.0000 | 1.0000 | 0.5000 | 42.48 kb |
ef core | 'first (no tracking)' | post | 250.59 us | 25 | 3.7500 | 0.7500 | 0.2500 | 21.44 kb |
nhibernate | criteria | post | 256.87 us | 26 | 11.0000 | 1.0000 | - | 65.64 kb |
ef 6 | 'first (no tracking)' | post | 314.69 us | 27 | 9.0000 | 1.0000 | - | 55.27 kb |
nhibernate | sql | post | 336.02 us | 28 | 19.0000 | 1.0000 | - | 101.4 kb |
freesql | first | post | 429.83 us | 29 | 5.0000 | 1.0000 | 0.5000 | 31.56 kb |
sqlsugar | first | post | 583.49 us | 30 | 10.0000 | 1.0000 | - | 62.5 kb |
linq to sql | first | post | 761.03 us | 31 | 3.0000 | 1.0000 | - | 14.7 kb |
nhibernate | linq | post | 778.43 us | 32 | 10.0000 | 2.0000 | - | 64.03 kb |