在2022年1月份本人做过一次sqlsugar,hisql,freesql三个框架的性能测试,上次主要是测的sqlserver下的常规插入(非bulkcopy的方式数据插入),hisql与目前比较流行的ORM框架性能测试对比 时间已经过半年,这次我就测的更完整点测试方案如下

测试方案

  1. 测试四种数据库(sqlserver,mysql,oralce,postgresql) 每种数据库写一遍测试文章
  2. 常规插入和批量插入
  3. 数据量从5条到100W间的数据插入
  4. 数据列从5列和50列的各种数据类型场景
  5. 开源测试代码供各位网友查看审核是否测试公平公正

测试源码https://github.com/tansar/HiSqlTestDemo

测试环境

操作系统环境

sqlserver 环境

mysql 环境

oracle 环境

postgresql 环境

sqlserver 常规数据插入测试

10列以下字段测试代码如下

  public static void TestSqlServerInsert(int _count)
{ //hisql连接 请先配置好数据库连接
HiSqlClient sqlClient = Demo_Init.GetSqlClient();
//hisql需要初始货安装 只需要执行一次
sqlClient.CodeFirst.InstallHisql(); //freesql连接
IFreeSql freeClient = Demo_Init.GetFreeSqlClient(); //sqlsugar连接
SqlSugarClient sugarClient = Demo_Init.GetSugarClient(); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest01)); Console.WriteLine("初始化hisql专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest02)); Console.WriteLine("初始化sqlsugar专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest03));
Console.WriteLine("初始化freesql专用表成功!"); Console.WriteLine($"测试场景 Sqlserver 向表中插入{_count}条数据 常规数据插入)");
Console.WriteLine($"用常规数据插入最适应日常应用场景"); List<object> lstobj = new List<object>();
List<Table.HTest02> lstobj2 = new List<Table.HTest02>();
List<Table.HTest03> lstobj3 = new List<Table.HTest03>();
Random random = new Random(); //插入的参数值都随机产生 以免数据库执行相同SQL时会有缓存影响测试结果
for (int i = 0; i < _count; i++)
{
//hisql可以用实体类也可以用匿名类
lstobj.Add(new Table.HTest01 { SID = (i + 1), UName = $"hisql{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"hisql初始创建" }); //sqlsugar用匿句类报错用实体类
lstobj2.Add(new Table.HTest02 { SID = (i + 1), UName = $"sqlsugar{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"sqlsugar初始创建" });
lstobj3.Add(new Table.HTest03 { SID = (i + 1), UName = $"freesql{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"freesql初始创建" });
} //删除测试表中的数据
sqlClient.TrunCate("HTest01").ExecCommand();
sqlClient.TrunCate("HTest02").ExecCommand();
sqlClient.TrunCate("HTest03").ExecCommand(); Stopwatch sw = new Stopwatch(); #region freesql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------FreeSql 测试----------");
Console.WriteLine($"FreeSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp3 = freeClient.Queryable<Table.HTest03>().Where(w => w.Age < 0).ToList();
Console.WriteLine($"FreeSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
freeClient.Insert<Table.HTest03>(lstobj3).ExecuteAffrows(); sw.Stop();
Console.WriteLine($"FreeSql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region hisql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------HiSql 测试----------");
Console.WriteLine($"HiSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp1 = sqlClient.Query("HTest01").Field("*").Take(1).Skip(1).ToDynamic();
Console.WriteLine($"HiSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
sqlClient.Insert("HTest01", lstobj).ExecCommand();
sw.Stop();
Console.WriteLine($"hisql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion

50列字段测试代码如下

  public static void TestSqlServer50ColInsert(int _count)
{ //hisql连接 请先配置好数据库连接
HiSqlClient sqlClient = Demo_Init.GetSqlClient();
//hisql需要初始货安装 只需要执行一次
sqlClient.CodeFirst.InstallHisql(); //freesql连接
IFreeSql freeClient = Demo_Init.GetFreeSqlClient(); //sqlsugar连接
SqlSugarClient sugarClient = Demo_Init.GetSugarClient(); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C01)); Console.WriteLine("初始化hisql专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C02)); Console.WriteLine("初始化sqlsugar专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C03));
Console.WriteLine("初始化freesql专用表成功!"); Console.WriteLine($"测试场景 Sqlserver 向表中插入{_count}条数据 50列 常规数据插入)");
Console.WriteLine($"用常规数据插入最适应日常应用场景"); List<object> lstobj = new List<object>();
List<Table.H_Test50C02> lstobj2 = new List<Table.H_Test50C02>();
List<Table.H_Test50C03> lstobj3 = new List<Table.H_Test50C03>();
Random random = new Random(); //插入的参数值都随机产生 以免数据库执行相同SQL时会有缓存影响测试结果
for (int i = 0; i < _count; i++)
{
//hisql可以用实体类也可以用匿名类
lstobj.Add(new Table.H_Test50C01 {
Material=(900000+i).ToString(),
Batch=(30000000+i).ToString(),
TestNum1= random.Next(10,100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13= random.Next(10, 100),
TestNum14= random.Next(10, 100),
TestNum15= random.Next(10, 100),
TestStr1 = $"hisql{random.Next(1, 100).ToString()}",
TestStr2 = $"hisql{random.Next(1, 100).ToString()}",
TestStr3 = $"hisql{random.Next(1, 100).ToString()}",
TestStr4 = $"hisql{random.Next(1, 100).ToString()}",
TestStr5 = $"hisql{random.Next(1, 100).ToString()}",
TestStr6 = $"hisql{random.Next(1, 100).ToString()}",
TestStr7 = $"hisql{random.Next(1, 100).ToString()}",
TestStr8 = $"hisql{random.Next(1, 100).ToString()}",
TestStr9 = $"hisql{random.Next(1, 100).ToString()}",
TestStr10 = $"hisql{random.Next(1, 100).ToString()}",
TestStr11 = $"hisql{random.Next(1, 100).ToString()}",
TestStr12 = $"hisql{random.Next(1, 100).ToString()}",
TestStr13 = $"hisql{random.Next(1, 100).ToString()}",
TestStr14 = $"hisql{random.Next(1, 100).ToString()}",
TestStr15 = $"hisql{random.Next(1, 100).ToString()}",
TestDec1 = i+ random.Next(1, 10000)/3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"hisql初始创建" }); //sqlsugar用匿句类报错用实体类
lstobj2.Add(new Table.H_Test50C02
{
Material = (900000 + i).ToString(),
Batch = (30000000 + i).ToString(),
TestNum1 = random.Next(10, 100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13 = random.Next(10, 100),
TestNum14 = random.Next(10, 100),
TestNum15 = random.Next(10, 100),
TestStr1 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr2 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr3 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr4 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr5 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr6 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr7 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr8 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr9 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr10 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr11 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr12 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr13 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr14 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr15 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestDec1 = i + random.Next(1, 10000) / 3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10),
Descript = $"sqlsugar初始创建"
});
lstobj3.Add(new Table.H_Test50C03
{
Material = (900000 + i).ToString(),
Batch = (30000000 + i).ToString(),
TestNum1 = random.Next(10, 100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13 = random.Next(10, 100),
TestNum14 = random.Next(10, 100),
TestNum15 = random.Next(10, 100),
TestStr1 = $"freesql{random.Next(1, 100).ToString()}",
TestStr2 = $"freesql{random.Next(1, 100).ToString()}",
TestStr3 = $"freesql{random.Next(1, 100).ToString()}",
TestStr4 = $"freesql{random.Next(1, 100).ToString()}",
TestStr5 = $"freesql{random.Next(1, 100).ToString()}",
TestStr6 = $"freesql{random.Next(1, 100).ToString()}",
TestStr7 = $"freesql{random.Next(1, 100).ToString()}",
TestStr8 = $"freesql{random.Next(1, 100).ToString()}",
TestStr9 = $"freesql{random.Next(1, 100).ToString()}",
TestStr10 = $"freesql{random.Next(1, 100).ToString()}",
TestStr11 = $"freesql{random.Next(1, 100).ToString()}",
TestStr12 = $"freesql{random.Next(1, 100).ToString()}",
TestStr13 = $"freesql{random.Next(1, 100).ToString()}",
TestStr14 = $"freesql{random.Next(1, 100).ToString()}",
TestStr15 = $"freesql{random.Next(1, 100).ToString()}",
TestDec1 = i + random.Next(1, 10000) / 3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10),
Descript = $"freesql初始创建"
});
} //删除测试表中的数据
sqlClient.TrunCate("H_Test50C01").ExecCommand();
sqlClient.TrunCate("H_Test50C02").ExecCommand();
sqlClient.TrunCate("H_Test50C03").ExecCommand(); Stopwatch sw = new Stopwatch(); #region freesql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------FreeSql 测试----------");
Console.WriteLine($"FreeSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp3 = freeClient.Queryable<Table.H_Test50C03>().Where(w => w.TestDec1 < 0).ToList();
Console.WriteLine($"FreeSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
freeClient.Insert<Table.H_Test50C03>(lstobj3).ExecuteAffrows(); sw.Stop();
Console.WriteLine($"FreeSql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region hisql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------HiSql 测试----------");
Console.WriteLine($"HiSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp1 = sqlClient.Query("H_Test50C01").Field("*").Take(1).Skip(1).ToDynamic();
Console.WriteLine($"HiSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
sqlClient.Insert("H_Test50C01", lstobj).ExecCommand();
sw.Stop();
Console.WriteLine($"hisql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region sqlsugar
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------SqlSugar 测试----------");
Console.WriteLine($"SqlSugar 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp2 = sugarClient.Queryable<Table.H_Test50C03>("H_Test50C03").Where(w => w.TestDec1 < 1).ToList();
Console.WriteLine($"sqlsugar 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
sugarClient.Insertable(lstobj2).AS("H_Test50C03").ExecuteCommand();
sw.Stop();
Console.WriteLine($"sqlsugar 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion
}

测试结果

5条记录10列以下测试结果截图

5条记录50列测试结果截图

50条记录10列以下测试结果截图

50条记录50列测试结果截图

100条记录10列以下测试结果截图

100条记录50列测试结果截图

500条记录10列以下测试结果截图

500条记录50列测试结果截图

1000条记录10列以下测试结果截图

1000条记录50列测试结果截图

5000条记录10列以下测试结果截图

5000条记录50列测试结果截图

10000条记录10列以下测试结果截图

10000条记录50列测就结果截图

50000条记录10列以下测试结果截图

50000条记录50列测试结果截图

100000条记录10列以下测试结果截图

100000条记录50列测试结果截图

sqlsugar 在执行此操作时抛出异常

错误提示:System.Data.SqlClient.SqlException:“资源池“default”没有足够的系统内存来运行此查询

在单独只执行sqlsugar的测试样例依然报此错误 通过分析sqlsugar的底层执行逻辑是因为它把所有的插入都拼成了一个插入sql文档造成的

测试结果

sqlserver 批量(bulkcopy)数据插入测试

可能会有很多人认为如果大批量数据插入肯定不会用常规的方式插入应该用BulkCopy的方式插入,好,那么我们再来测测基于数据库厂商提供的SDK驱动自带的BulkCopy再来对比一下三个框架的性能

10列以下批量插入的bulkcopy测试代码

public static void TestSqlServerBulkCopy(int _count)
{ //hisql连接 请先配置好数据库连接
HiSqlClient sqlClient = Demo_Init.GetSqlClient();
//hisql需要初始货安装 只需要执行一次
sqlClient.CodeFirst.InstallHisql(); //freesql连接
IFreeSql freeClient = Demo_Init.GetFreeSqlClient(); //sqlsugar连接
SqlSugarClient sugarClient = Demo_Init.GetSugarClient(); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest01)); Console.WriteLine("初始化hisql专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest02)); Console.WriteLine("初始化sqlsugar专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.HTest03));
Console.WriteLine("初始化freesql专用表成功!"); Console.WriteLine($"测试场景 Sqlserver 向表中插入{_count}条数据 BulkCopy方式插入");
Console.WriteLine($"适用于大量数据导入场景"); List<object> lstobj = new List<object>();
List<Table.HTest02> lstobj2 = new List<Table.HTest02>();
List<Table.HTest03> lstobj3 = new List<Table.HTest03>();
Random random = new Random(); //插入的参数值都随机产生 以免数据库执行相同SQL时会有缓存影响测试结果
for (int i = 0; i < _count; i++)
{
//hisql可以用实体类也可以用匿名类
lstobj.Add(new Table.HTest01 { SID = (i + 1), UName = $"hisql{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"hisql初始创建" }); //sqlsugar用匿句类报错用实体类
lstobj2.Add(new Table.HTest02 { SID = (i + 1), UName = $"sqlsugar{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"sqlsugar初始创建" });
lstobj3.Add(new Table.HTest03 { SID = (i + 1), UName = $"freesql{i}", Age = 20 + (i % 50), Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"freesql初始创建" });
} //删除测试表中的数据
sqlClient.TrunCate("HTest01").ExecCommand();
sqlClient.TrunCate("HTest02").ExecCommand();
sqlClient.TrunCate("HTest03").ExecCommand(); Stopwatch sw = new Stopwatch(); #region freesql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------FreeSql 测试----------");
Console.WriteLine($"FreeSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp3 = freeClient.Queryable<Table.HTest03>().Where(w => w.Age < 0).ToList();
Console.WriteLine($"FreeSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
//freeClient.Insert<Table.HTest03>(lstobj3).ExecuteAffrows();
freeClient.Insert<Table.HTest03>(lstobj3).ExecuteSqlBulkCopy();
sw.Stop();
Console.WriteLine($"FreeSql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region hisql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------HiSql 测试----------");
Console.WriteLine($"HiSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp1 = sqlClient.Query("HTest01").Field("*").Take(1).Skip(1).ToDynamic();
Console.WriteLine($"HiSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
//sqlClient.Insert("HTest01", lstobj).ExecCommand(); sqlClient.BulkCopyExecCommand("HTest01", lstobj);
sw.Stop();
Console.WriteLine($"hisql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region sqlsugar
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------SqlSugar 测试----------");
Console.WriteLine($"SqlSugar 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp2 = sugarClient.Queryable<Table.HTest02>("HTest02").Where(w => w.Age < 1).ToList();
Console.WriteLine($"sqlsugar 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
//sugarClient.Insertable(lstobj2).AS("HTest02").ExecuteCommand();
sugarClient.Fastest<Table.HTest02>().BulkCopy(lstobj2);
sw.Stop();
Console.WriteLine($"sqlsugar 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion
}

50列批量插入的bulkcopy测试代码

public static void TestSqlServer50ColInsert(int _count)
{ //hisql连接 请先配置好数据库连接
HiSqlClient sqlClient = Demo_Init.GetSqlClient();
//hisql需要初始货安装 只需要执行一次
sqlClient.CodeFirst.InstallHisql(); //freesql连接
IFreeSql freeClient = Demo_Init.GetFreeSqlClient(); //sqlsugar连接
SqlSugarClient sugarClient = Demo_Init.GetSugarClient(); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C01)); Console.WriteLine("初始化hisql专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C02)); Console.WriteLine("初始化sqlsugar专用表成功!"); sqlClient.CodeFirst.CreateTable(typeof(Table.H_Test50C03));
Console.WriteLine("初始化freesql专用表成功!"); Console.WriteLine($"测试场景 Sqlserver 向表中插入{_count}条数据 50列 常规数据插入)");
Console.WriteLine($"适用于大量数据导入场景"); List<object> lstobj = new List<object>();
List<Table.H_Test50C02> lstobj2 = new List<Table.H_Test50C02>();
List<Table.H_Test50C03> lstobj3 = new List<Table.H_Test50C03>();
Random random = new Random(); //插入的参数值都随机产生 以免数据库执行相同SQL时会有缓存影响测试结果
for (int i = 0; i < _count; i++)
{
//hisql可以用实体类也可以用匿名类
lstobj.Add(new Table.H_Test50C01 {
Material=(900000+i).ToString(),
Batch=(30000000+i).ToString(),
TestNum1= random.Next(10,100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13= random.Next(10, 100),
TestNum14= random.Next(10, 100),
TestNum15= random.Next(10, 100),
TestStr1 = $"hisql{random.Next(1, 100).ToString()}",
TestStr2 = $"hisql{random.Next(1, 100).ToString()}",
TestStr3 = $"hisql{random.Next(1, 100).ToString()}",
TestStr4 = $"hisql{random.Next(1, 100).ToString()}",
TestStr5 = $"hisql{random.Next(1, 100).ToString()}",
TestStr6 = $"hisql{random.Next(1, 100).ToString()}",
TestStr7 = $"hisql{random.Next(1, 100).ToString()}",
TestStr8 = $"hisql{random.Next(1, 100).ToString()}",
TestStr9 = $"hisql{random.Next(1, 100).ToString()}",
TestStr10 = $"hisql{random.Next(1, 100).ToString()}",
TestStr11 = $"hisql{random.Next(1, 100).ToString()}",
TestStr12 = $"hisql{random.Next(1, 100).ToString()}",
TestStr13 = $"hisql{random.Next(1, 100).ToString()}",
TestStr14 = $"hisql{random.Next(1, 100).ToString()}",
TestStr15 = $"hisql{random.Next(1, 100).ToString()}",
TestDec1 = i+ random.Next(1, 10000)/3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10), Descript = $"hisql初始创建" }); //sqlsugar用匿句类报错用实体类
lstobj2.Add(new Table.H_Test50C02
{
Material = (900000 + i).ToString(),
Batch = (30000000 + i).ToString(),
TestNum1 = random.Next(10, 100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13 = random.Next(10, 100),
TestNum14 = random.Next(10, 100),
TestNum15 = random.Next(10, 100),
TestStr1 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr2 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr3 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr4 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr5 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr6 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr7 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr8 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr9 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr10 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr11 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr12 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr13 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr14 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestStr15 = $"sqlsugar{random.Next(1, 100).ToString()}",
TestDec1 = i + random.Next(1, 10000) / 3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10),
Descript = $"sqlsugar初始创建"
});
lstobj3.Add(new Table.H_Test50C03
{
Material = (900000 + i).ToString(),
Batch = (30000000 + i).ToString(),
TestNum1 = random.Next(10, 100),
TestNum2 = random.Next(10, 100),
TestNum3 = random.Next(10, 100),
TestNum4 = random.Next(10, 100),
TestNum5 = random.Next(10, 100),
TestNum6 = random.Next(10, 100),
TestNum7 = random.Next(10, 100),
TestNum8 = random.Next(10, 100),
TestNum9 = random.Next(10, 100),
TestNum10 = random.Next(10, 100),
TestNum11 = random.Next(10, 100),
TestNum12 = random.Next(10, 100),
TestNum13 = random.Next(10, 100),
TestNum14 = random.Next(10, 100),
TestNum15 = random.Next(10, 100),
TestStr1 = $"freesql{random.Next(1, 100).ToString()}",
TestStr2 = $"freesql{random.Next(1, 100).ToString()}",
TestStr3 = $"freesql{random.Next(1, 100).ToString()}",
TestStr4 = $"freesql{random.Next(1, 100).ToString()}",
TestStr5 = $"freesql{random.Next(1, 100).ToString()}",
TestStr6 = $"freesql{random.Next(1, 100).ToString()}",
TestStr7 = $"freesql{random.Next(1, 100).ToString()}",
TestStr8 = $"freesql{random.Next(1, 100).ToString()}",
TestStr9 = $"freesql{random.Next(1, 100).ToString()}",
TestStr10 = $"freesql{random.Next(1, 100).ToString()}",
TestStr11 = $"freesql{random.Next(1, 100).ToString()}",
TestStr12 = $"freesql{random.Next(1, 100).ToString()}",
TestStr13 = $"freesql{random.Next(1, 100).ToString()}",
TestStr14 = $"freesql{random.Next(1, 100).ToString()}",
TestStr15 = $"freesql{random.Next(1, 100).ToString()}",
TestDec1 = i + random.Next(1, 10000) / 3,
TestDec2 = i + random.Next(1, 10000) / 3,
TestDec3 = i + random.Next(1, 10000) / 3,
TestDec4 = i + random.Next(1, 10000) / 3,
TestDec5 = i + random.Next(1, 10000) / 3,
TestDec6 = i + random.Next(1, 10000) / 3,
TestDec7 = i + random.Next(1, 10000) / 3,
TestDec8 = i + random.Next(1, 10000) / 3,
TestDec9 = i + random.Next(1, 10000) / 3,
TestDec10 = i + random.Next(1, 10000) / 3,
TestDec11 = i + random.Next(1, 10000) / 3,
TestDec12 = i + random.Next(1, 10000) / 3,
TestDec13 = i + random.Next(1, 10000) / 3,
TestDec14 = i + random.Next(1, 10000) / 3,
TestDec15 = i + random.Next(1, 10000) / 3,
Salary = 5000 + (i % 2000) + random.Next(10),
Descript = $"freesql初始创建"
});
} //删除测试表中的数据
sqlClient.TrunCate("H_Test50C01").ExecCommand();
sqlClient.TrunCate("H_Test50C02").ExecCommand();
sqlClient.TrunCate("H_Test50C03").ExecCommand(); Stopwatch sw = new Stopwatch(); #region freesql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------FreeSql 测试----------");
Console.WriteLine($"FreeSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp3 = freeClient.Queryable<Table.H_Test50C03>().Where(w => w.TestDec1 < 0).ToList();
Console.WriteLine($"FreeSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
freeClient.Insert<Table.H_Test50C03>(lstobj3).ExecuteAffrows(); sw.Stop();
Console.WriteLine($"FreeSql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region hisql
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------HiSql 测试----------");
Console.WriteLine($"HiSql 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp1 = sqlClient.Query("H_Test50C01").Field("*").Take(1).Skip(1).ToDynamic();
Console.WriteLine($"HiSql 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
sqlClient.Insert("H_Test50C01", lstobj).ExecCommand();
sw.Stop();
Console.WriteLine($"hisql 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion #region sqlsugar
sw.Reset();
Console.WriteLine("------------------------------");
Console.WriteLine("----------SqlSugar 测试----------");
Console.WriteLine($"SqlSugar 预热...{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
var temp2 = sugarClient.Queryable<Table.H_Test50C03>("H_Test50C03").Where(w => w.TestDec1 < 1).ToList();
Console.WriteLine($"sqlsugar 正在插入数据\t{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
sw.Start();
sugarClient.Insertable(lstobj2).AS("H_Test50C03").ExecuteCommand();
sw.Stop();
Console.WriteLine($"sqlsugar 数据插入{_count}条 耗时{sw.Elapsed}秒");
sw.Reset();
#endregion
}

测试结果

1W条数据10列以下字段bulkcopy插入测试

1W条数据50列字段bulkcopy插入测试

5W条数据10列以下字段bulkcpy插入测试

5W条数据50列字段bulkcopy插入测试

10W条数据10列以下字段Bulkcopy插入测试

10W条数据50列字段bulkcopy插入测试

20w条数据10列以下字段bulkcopy插入测试

20w条数据50列字段bulkcopy插入测试

50w条数据10列字段Bulkcopy插入测试

50w条数据50列字段BulkCopy插入测试

100W条10列以下字段bulkCopy插入测试

100W条数据50列字段bulkcopy插入测试

测试结果

总结

我想不用总结了 三个ORM不管是按常规插入和bulkcopy插入谁快认慢一目了然,不过我还是想贴上以下图

c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试的更多相关文章

  1. c# 国内外ORM 框架 dapper efcore sqlsugar freesql hisql sqlserver数据常规插入测试性能对比

    c# 国内外ORM 框架 dapper efcore sqlsugar freesql hisql sqlserver数据常规插入测试性能对比对比 在6.22 号发布了 c# sqlsugar,his ...

  2. .NET ORM框架 SqlSuagr4.0 功能详解与实践【开源】

    SqlSugar 4.0 ORM框架的优势 为了未来能够更好的支持多库分布式的存储,并行计算等功能,将SqlSugar3.x全部重写,现有的架构可以轻松扩展多库. 源码下载: https://gith ...

  3. .NET ORM框架 SqlSugar4.0 功能快速预览【开源】

    SqlSugar 4.0 ORM框架的优势 为了未来能够更好的支持多库分布式的存储,并行计算等功能,将SqlSugar3.x全部重写,现有的架构可以轻松扩展多库. 源码下载: https://gith ...

  4. sqlsugar freesql hisql 三个ORM框架性能测试对比

    hisql与目前比较流行的ORM框架性能测试对比 总体测试结果 插入记录数 hisql(耗时) sqlsugar(耗时) freesql(耗时) 5条 0.0107秒 0.0312秒 0.02675秒 ...

  5. hisql ORM 框架研究(国内第一个支持HANA的ORM框架)

    HiSql 操作说明文档 V1.0 下一代ORM框架 国内第一个支持HANA的ORM框架 hisql源码下载 git clone https://github.com/tansar/HiSql.git ...

  6. hisql orm 框架insert数据写入教程

    hisql.net 官网(文档编写中) HiSql 源码(github) https://github.com/tansar/HiSql git clone https://github.com/ta ...

  7. .NET ORM框架HiSql实战-第一章-集成HiSql

    一.引言 做.Net这么多年,出现了很多很多ORM框架,比如Dapper,Sqlsugar,Freesql等等.在之前的项目中,用到的ORM框架也大多数是这几个老牌的框架. 不过最近园子关于.NET ...

  8. .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)

    一.引言 上一篇.NET ORM框架HiSql实战-第一章-集成HiSql 已经完成了Hisql的引入,本节就把 项目中的菜单管理改成hisql的方式实现. 菜单管理界面如图: 二.修改增删改查相关代 ...

  9. .Net开源SqlServer ORM框架SqlSugar整理

    一.链接整理 官方Git源代码地址: https://github.com/sunkaixuan/SqlSugar 最新发布版更新地址:当前版本Release 3.5.2.1 https://gith ...

随机推荐

  1. zabbix使用自带模板监控MySQL

    监控mysql不能直接使用zabbix自带模板,还需要到被监控的mysql客户端做配置. 1.在zabbix   web配置步骤如下图: 2.配置完之后去看mysql主机监控项的时候看到mysql的监 ...

  2. python中faker模块的使用

    Faker 安装 pip install Faker 基本使用 from faker import Faker #创建对象,默认生成的数据为为英文,使用zh_CN指定为中文 fake = Faker( ...

  3. STL空间分配器源码分析(一)

    一.摘要 STL的空间分配器(allocator)定义于命名空间std内,主要为STL容器提供内存的分配和释放.对象的构造和析构的统一管理.空间分配器的实现细节,对于容器来说完全透明,容器不需关注内存 ...

  4. 超详细讲解H5移动端适配

    前言 移动互联网发展至今,各种移动设备应运而生,但它们的物理分辨率可以说是五花八门,一般情况UI会为我们提供375尺寸的设计稿,所以为了让H5页面能够在这些不同的设备上尽量表现的一致,前端工程师就不得 ...

  5. partOneJava学习卷土重来-----第一次测试题目介绍

    石家庄铁道大学2021年秋季   2020 级课堂测试试卷(一)(15分) 课程名称: JAVA语言程序设计  任课教师: 王建民        考试时间: 150 分钟 一.考试要求: 1.按照测试 ...

  6. (2020行人再识别综述)Person Re-Identification using Deep Learning Networks: A Systematic Review

    目录 1.引言 2.研究方法 2.1本次综述的贡献 2.2综述方法 2.3与现有综述的比较 3.行人再识别基准数据集 3.1基于图像的再识别数据集 3.2基于视频的再识别数据集 4.基于图像的深度再识 ...

  7. DevOps转型到底值不值?

    摘要:企业进行DevOps转型是否有价值?是否能计算出明确的投资回报率呢?本文将为您解惑. 本文分享自华为云社区<DevOps转型到底值不值?>,作者:敏捷小智 . 引言 企业都是以盈利为 ...

  8. 被人DDoS攻击了,分析一下原理和防护

    一.行业现象 1.1 为什么要攻击? 常见的,一个是同行恶意竞争,一个是敲诈勒索. 无论是传统行业的线下门店,还是互联网行业的门户网站.APP产品,都存在着竞争关系,争相获得更多客源,究其目的,无非是 ...

  9. 终极套娃 2.0|云原生 PaaS 平台的可观测性实践分享

    某个周一上午,小涛像往常一样泡上一杯热咖啡 ️,准备打开项目协同开始新一天的工作,突然隔壁的小文喊道:"快看,用户支持群里炸锅了 -" 用户 A:"Git 服务有点问题, ...

  10. [AcWing 800] 数组元素的目标和

    点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], b[N]; int mai ...