本次测试只测试以下几点
- Expression表达式解析,生成SQL的效率
- 数据转实体的效率
- 多次查询效率
测试环境
- 数据库Sqlite
- net6.0
- 测试框架Benchmark
以EF为例
只调用SQL语句生成
public override void testQueryCondition() { using (var context = new efContext()) { var filter = GetSelectFilter(); var query = context.Set<TestEntity>().AsQueryable(); var sql = query.Where(filter).ToQueryString(); } }
直接返回对象或匿名对象
public override void testQueryResult() { using (var context = new efContext()) { var query = context.Set<TestEntity>().AsQueryable(); var list = query.Take(listTake).Select(b => new { b.Id, b.F_Float, b.F_Bool, b.F_DateTime, b.F_Decimal, b.F_Double, b.F_Int64 }).ToList(); } }
循环多次调用
public override void testQueryLoop() { for (var i = 0; i < 20; i++) { using (var context = new efContext()) { var query = context.Set<TestEntity>().AsQueryable(); var list = query.Where(b => b.Id == i).ToList(); } } }
测试结果(仅供参考)
具体测试代码参见下文源码
结果1
Method | ProvideType | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated |
---|---|---|---|---|---|---|---|---|
TestResult | myTest | 746.7 μs | 15.26 μs | 44.52 μs | 730.7 μs | 21.4844 | - | 68.67 KB |
TestResult | ChloeTest | 1,818.3 μs | 41.93 μs | 123.64 μs | 1,797.1 μs | 31.2500 | - | 98.62 KB |
TestResult | DapperTest | 536.5 μs | 11.61 μs | 34.04 μs | 528.5 μs | 16.6016 | - | 52.66 KB |
TestResult | EfSqlliteTest | 623.3 μs | 12.41 μs | 30.21 μs | 617.9 μs | 33.2031 | - | 103.05 KB |
TestResult | FastFrameworkTest | 2,756.5 μs | 29.31 μs | 25.98 μs | 2,754.0 μs | 121.0938 | - | 377.39 KB |
TestResult | FreeSqlTest | 2,367.3 μs | 47.29 μs | 107.71 μs | 2,341.8 μs | 66.4063 | 11.7188 | 210.1 KB |
TestResult | SqlSugarTest | 1,742.2 μs | 121.07 μs | 339.49 μs | 1,655.3 μs | 46.8750 | - | 147.29 KB |
结果2
Method | ProvideType | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated |
---|---|---|---|---|---|---|---|---|
TestCondition | myTest | 14,131.69 ns | 282.276 ns | 782.187 ns | 13,958.35 ns | 1.7548 | 0.4272 | 5537 B |
TestCondition | ChloeTest | 595,894.06 ns | 14,617.505 ns | 43,100.044 ns | 598,357.47 ns | 9.7656 | - | 31965 B |
TestCondition | DapperTest | 63.32 ns | 1.607 ns | 4.738 ns | 63.46 ns | 0.0280 | - | 88 B |
TestCondition | EfSqlliteTest | 166,956.69 ns | 3,217.466 ns | 9,283.124 ns | 164,359.72 ns | 17.8223 | - | 55989 B |
TestCondition | FastFrameworkTest | 616,365.41 ns | 12,669.876 ns | 37,158.552 ns | 617,112.30 ns | 8.7891 | - | 30053 B |
TestCondition | FreeSqlTest | 1,058,620.61 ns | 10,821.173 ns | 10,122.132 ns | 1,060,617.77 ns | 5.8594 | 1.9531 | 46019 B |
TestCondition | SqlSugarTest | 186,503.97 ns | 1,451.859 ns | 1,212.368 ns | 186,146.95 ns | 21.7285 | - | 68511 B |
结果3
Method | ProvideType | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated |
---|---|---|---|---|---|---|---|---|
TestQueryLoop | myTest | 2.112 ms | 0.0306 ms | 0.0239 ms | 2.118 ms | 42.9688 | - | 149.8 KB |
TestQueryLoop | ChloeTest | 29.754 ms | 0.7137 ms | 2.0707 ms | 29.819 ms | 250.0000 | - | 782.76 KB |
TestQueryLoop | DapperTest | 1.532 ms | 0.0308 ms | 0.0908 ms | 1.538 ms | 17.5781 | - | 53.94 KB |
TestQueryLoop | EfSqlliteTest | 5.885 ms | 0.1144 ms | 0.2463 ms | 5.795 ms | 375.0000 | - | 1155.08 KB |
TestQueryLoop | FastFrameworkTest | 59.503 ms | 0.6741 ms | 0.5976 ms | 59.539 ms | 3000.0000 | - | 9259.67 KB |
TestQueryLoop | FreeSqlTest | 29.067 ms | 0.5529 ms | 0.6790 ms | 29.158 ms | 125.0000 | 62.5000 | 873.88 KB |
TestQueryLoop | SqlSugarTest | 4.315 ms | 0.0369 ms | 0.0346 ms | 4.315 ms | 203.1250 | - | 644.42 KB |
测试代码下载 https://files.cnblogs.com/files/hubro/dbTest.rar?t=1700470723&download=true
发布后运行结果更准确
运行输入序号即开始测试
标签:KB,测试,TestCondition,喜闻乐见,ORM,ms,TestQueryLoop,var,ns From: https://www.cnblogs.com/hubro/p/17844362.html