1.统一使用Realse版本的最新 DLL,Realse模式启用程序
2.为了平衡CPU和数据库空闲情况,使用车轮战,每场比赛连续10回合比试
3.多次重启电脑取平均成绩上图
1.SqlSugar 3.1.01
2.Dapper 1.5.0.2 Dapper.Contrib 1.5 官方DLL
每次查询100万条数据
SqlSugar 100分 Dapper95分
比赛结果: SqlSugar小胜
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class SelectBigData : IDemos { /// <summary> /// 测试一次读取100万条数据的速度 /// </summary> public void Init() { Console.WriteLine("测试一次读取100万条数据的速度"); var eachCount = 1; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //dapper Dapper(eachCount); //sqlSugar SqlSugar(eachCount); } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.Queryable<Test>().ToList(); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.GetAll<Test>(); } }); } } } |
SqlSugar 100分 Dapper 100分
比赛结果:平手
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class SelectSingle : IDemos { /// <summary> /// 测试一次读取1条,每次执行1000次 /// </summary> public void Init() { Console.WriteLine("测试一次读取1条"); var eachCount = 1000; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //dapper Dapper(eachCount); //sqlSugar SqlSugar(eachCount); } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.Queryable<Test>().InSingle(1000); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Get<Test>(1000); } }); } } } |
SqlSugar 100分 Dapper 60分
比赛结果:SqlSugar胜出
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class UpdateList : IDemos { public void Init() { Console.WriteLine("测试更新1000条的集合"); var eachCount = 10; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //dapper Dapper(eachCount); //sqlSugar SqlSugar(eachCount); } } private static List<Test> GetList { get { List<Test> list = new List<Test>(); for (int i = 1000; i < 2000; i++) { Test t = new Test() { Id=i, F_Int32 = 1, F_String = "Test", F_Float = 1, F_DateTime = DateTime.Now, F_Byte = 1, F_Bool = true }; list.Add(t); } return list; } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.SqlBulkReplace(GetList); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Update(GetList); } }); } } } |
SqlSugar 100分 Dapper 12分
比赛结果:SqlSugar胜出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class InsertList : IDemos { public void Init() { Console.WriteLine("测试插入1000条记录的集合"); var eachCount = 10; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //清除 DeleteAddDatas(); //dapper Dapper(eachCount); //清除 DeleteAddDatas(); //sqlSugar SqlSugar(eachCount); } Console.WriteLine("SqlSugar批量插入性能,秒杀Dapper一条街。(Dapper并没有优化过)"); } private static void DeleteAddDatas() { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { conn.Delete<Test>(it => it.F_String == "Test"); } } private static List<Test> GetList { get { List<Test> list = new List<Test>(); for (int i = 0; i < 1000; i++) { Test t = new Test() { F_Int32 = 1, F_String = "Test", F_Float = 1, F_DateTime = DateTime.Now, F_Byte = 1, F_Bool = true }; list.Add(t); } return list; } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.SqlBulkCopy(GetList); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Insert(GetList); } }); } } } |
SqlSugar 100分 Dapper 50分
比赛结果:SqlSugar胜出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class DeleteArray : IDemos { public void Init() { Console.WriteLine("测试删除1000条的集合"); var eachCount = 10; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //dapper Dapper(eachCount); //sqlSugar SqlSugar(eachCount); } } /// <summary> /// 查询出刚插入的1000条数据 /// </summary> /// <returns></returns> private static List<Test> GetDeleteList() { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { conn.Delete<Test>(it => it.F_String == "Test"); //插入1000条 conn.SqlBulkCopy(GetList); //查询出插入的1000条 var list = conn.Queryable<Test>().Where(it => it.F_String == "Test").ToList(); return list; } } private static List<Test> GetList { get { List<Test> list = new List<Test>(); for (int i = 1; i < 1000; i++) { Test t = new Test() { F_Int32 = 1, F_String = "Test", F_Float = 1, F_DateTime = DateTime.Now, F_Byte = 1, F_Bool = true }; list.Add(t); } return list; } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var ids = GetDeleteList().Select(it => it.Id).ToArray(); var list = conn.Delete<Test,int>(ids); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var delList = GetDeleteList(); var list = conn.Delete(delList); } }); } } } |
SqlSugar 96分 Dapper 100分
比赛结果:Dapper小胜
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class Page : IDemos { public void Init() { Console.WriteLine("分页"); var eachCount = 3000; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //dapper Dapper(eachCount); //sqlSugar SqlSugar(eachCount); } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.SqlQuery<Test>("select * from(select *,row_number() over(order by id) as r from test ) t where t.r between @b and @e ", new { b = 1000, e = 1010 }); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Query<Test>("select * from(select *,row_number() over(order by id) as r from test ) t where t.r between @b and @e ", new { b = 1000, e = 1010 }); } }); } } } |
SqlSugar 100分 Dapper 96分
比赛结果: SqlSugar小胜
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Dapper; using Dapper.Contrib; using Dapper.Contrib.Extensions; using Models.PkDapper; using SqlSugar; using SyntacticSugar; namespace PkDapper.Demos { public class InsertItem : IDemos { public void Init() { Console.WriteLine("测试插入单条记录"); var eachCount = 1000; /*******************车轮战是性能评估最准确的一种方式***********************/ for (int i = 0; i < 10; i++) { //清除 DeleteAddDatas(); //dapper Dapper(eachCount); //清除 DeleteAddDatas(); //sqlSugar SqlSugar(eachCount); } } private static void DeleteAddDatas() { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { conn.Delete<Test>(it => it.F_String == "Test"); } } private static Test GetItem { get { Test t = new Test() { F_Int32 = 1, F_String = "Test", F_Float = 1, F_DateTime = DateTime.Now, F_Byte = 1, F_Bool = true }; return t; } } private static void SqlSugar(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 PerHelper.Execute(eachCount, "SqlSugar", () => { using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.Insert(GetItem); } }); } private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Insert(GetItem); } }); } } } |
SqlSugar 90分 Dapper 100分
比赛结果:Dapper小胜
Dapper在批量操作上性能不尽人意,普通查询 增 删 和改 速度可以接受,想了解SqlSugar可以看这篇文章
http://www.cnblogs.com/sunkaixuan/p/5911334.html
测试代码:
有兴趣的朋友可以下载测试,也可以方便的加上其它ORM
https://github.com/sunkaixuan/SqlSugar
from:https://www.cnblogs.com/sunkaixuan/p/5951388.html