Src/Asp.NetCore2/PerformanceBenchmarks/README.md
这是 SqlSugar ORM 的综合性能基准测试套件,用于比较 SqlSugar 与其他流行 ORM(如 Dapper、Entity Framework Core)的性能表现。
This is a comprehensive performance benchmark suite for SqlSugar ORM, designed to compare SqlSugar's performance with other popular ORMs like Dapper and Entity Framework Core.
# 1. Configure database connection in BenchmarkConfig.cs
# 在 BenchmarkConfig.cs 中配置数据库连接
# 2. Run validation tests / 运行验证测试
.\RunTests.ps1
# 3. Run full benchmarks / 运行完整基准测试
dotnet run -c Release
✅ 查询基准测试 / Query Benchmarks
✅ 插入基准测试 / Insert Benchmarks
✅ 更新基准测试 / Update Benchmarks
✅ 删除基准测试 / Delete Benchmarks
✅ 批量操作基准测试 / Bulk Operation Benchmarks
✅ 联接查询基准测试 / Join Query Benchmarks
✅ 复杂查询基准测试 / Complex Query Benchmarks
Before running benchmarks, validate your setup:
在运行基准测试之前,验证您的设置:
# Using PowerShell script (Recommended) / 使用 PowerShell 脚本(推荐)
.\RunTests.ps1
# Or using dotnet CLI / 或使用 dotnet CLI
dotnet run -c Release -- --test
Tests Include / 测试包括:
Test 1: Database Connection... ✓ PASSED
Test 2: Entity Creation... ✓ PASSED
Test 3: Basic CRUD Operations... ✓ PASSED
Test 4: Bulk Operations... ✓ PASSED
Test 5: Join Queries... ✓ PASSED
Test 6: Navigation Properties... ✓ PASSED
✓ All validation tests PASSED!
在运行基准测试之前,请修改 BenchmarkConfig.cs 中的数据库连接字符串:
Before running benchmarks, modify the database connection strings in BenchmarkConfig.cs:
public const string SqlServerConnection = "server=.;uid=sa;pwd=YOUR_PASSWORD;database=SqlSugarBenchmark;Encrypt=True;TrustServerCertificate=True";
cd d:\dev\bit\74\SqlSugar\Src\Asp.NetCore2\PerformanceBenchmarks
dotnet run -c Release
dotnet run -c Release -- --test
dotnet run -c Release -- --filter *QueryBenchmarks*
比较 SqlSugar 和 Dapper 在各种查询场景下的性能:
Compares SqlSugar and Dapper performance across various query scenarios:
SqlSugar_SimpleQuery - 简单查询SqlSugar_PaginationQuery - 分页查询SqlSugar_ComplexQuery - 复杂条件查询SqlSugar_QueryById - 按 ID 查询SqlSugar_DynamicQuery - 动态条件查询SqlSugar_SelectColumns - 查询指定列测试各种插入操作的性能:
Tests performance of various insert operations:
SqlSugar_SingleInsert - 单条插入SqlSugar_BatchInsert_100 - 批量插入 100 条SqlSugar_InsertReturnIdentity - 插入并返回自增 IDSqlSugar_BatchInsertReturnPKs - 批量插入并返回主键列表SqlSugar_InsertIgnoreColumns - 插入时忽略指定列测试各种更新操作的性能:
Tests performance of various update operations:
SqlSugar_SingleUpdate - 单条更新SqlSugar_UpdateColumns - 更新指定列SqlSugar_BatchUpdate - 批量更新SqlSugar_UpdateWithCondition - 条件更新SqlSugar_UpdateIgnoreColumns - 更新时忽略指定列测试各种删除操作的性能:
Tests performance of various delete operations:
SqlSugar_DeleteByEntity - 按实体删除SqlSugar_DeleteById - 按 ID 删除SqlSugar_DeleteWithCondition - 条件删除SqlSugar_DeleteByIdList - 按 ID 列表删除测试 SqlSugar 的高性能批量操作:
Tests SqlSugar's high-performance bulk operations:
SqlSugar_BulkCopy_1000 - BulkCopy 插入 1000 条SqlSugar_BatchInsert_1000 - 常规批量插入 1000 条SqlSugar_BulkUpdate_1000 - 批量更新 1000 条SqlSugar_Storageable_1000 - 存储(插入或更新)1000 条SqlSugar_BulkMerge_1000 - 批量合并 1000 条SqlSugar_BulkCopy_DataTable - 使用 DataTable 的 BulkCopy测试各种联接查询的性能:
Tests performance of various join queries:
SqlSugar_InnerJoin - 内联接SqlSugar_LeftJoin - 左联接SqlSugar_MultipleJoins - 多表联接SqlSugar_JoinWithWhere - 带条件的联接SqlSugar_JoinWithGroupBy - 带分组的联接测试复杂查询场景的性能:
Tests performance of complex query scenarios:
SqlSugar_Subquery - 子查询SqlSugar_GroupByWithHaving - 分组查询带 HavingSqlSugar_UnionQuery - Union 查询SqlSugar_IncludeNavigation - 包含导航属性SqlSugar_MultipleIncludes - 多个导航属性SqlSugar_DynamicExpression - 动态表达式查询SqlSugar_DistinctQuery - 去重查询SqlSugar_AggregateFunctions - 聚合函数SqlSugar_InQuery - In 查询基准测试使用以下实体和数据量:
Benchmarks use the following entities and data volumes:
BenchmarkDotNet 会生成详细的性能报告,包括:
BenchmarkDotNet generates detailed performance reports including:
| Method | Mean | Error | StdDev | Allocated |
|-------------------------- |----------:|----------:|----------:|----------:|
| SqlSugar_SimpleQuery | 1.234 ms | 0.0123 ms | 0.0115 ms | 12.5 KB |
| Dapper_SimpleQuery | 1.456 ms | 0.0145 ms | 0.0136 ms | 13.2 KB |
基于基准测试结果,以下是一些性能优化建议:
Based on benchmark results, here are some performance optimization tips:
批量操作 / Bulk Operations
BulkCopy 而不是循环插入BulkCopy instead of loop inserts for large data volumes查询优化 / Query Optimization
Select 指定需要的列,避免查询所有列Select to specify needed columns, avoid selecting all columns分页查询 / Pagination
ToPageList 进行分页,性能优于手动分页ToPageList for pagination, better performance than manual pagination导航属性 / Navigation Properties
Includes,只加载需要的导航属性Includes carefully, only load needed navigation properties缓存 / Caching
欢迎提交新的基准测试场景或改进现有测试!
Welcome to submit new benchmark scenarios or improve existing tests!
git checkout -b feature/new-benchmark)git commit -am 'Add new benchmark')git push origin feature/new-benchmark)Error / 错误: A network-related or instance-specific error occurred
Solutions / 解决方案:
BenchmarkConfig.csError / 错误: The type or namespace name could not be found
Solutions / 解决方案:
dotnet restore
dotnet clean
dotnet build -c Release
This is normal. Full benchmark suite takes 30-60 minutes.
这是正常的。完整的基准测试套件需要 30-60 分钟。
Use --filter to run specific tests:
dotnet run -c Release -- --filter *QueryBenchmarks*
本项目遵循 SqlSugar 项目的 MIT 许可证。
This project follows SqlSugar's MIT License.
如有问题或建议,请在 GitHub Issues 中提出。
For questions or suggestions, please submit them in GitHub Issues.
Version / 版本: 1.0.0
Status / 状态: ✅ Production Ready
Last Updated / 最后更新: 2025-11-08
Happy Benchmarking! / 测试愉快! 🚀