FreeSql 与 SqlSugar 性能测试
时间:2019-03-19
本文章向大家介绍FreeSql 与 SqlSugar 性能测试,主要包括FreeSql 与 SqlSugar 性能测试使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
这篇文章受大家邀请,与 SqlSugar 做一次简单的性能测试对比。主要针对插入、批量插入、批量更新、读取性能的测试;
测试环境
- .net core 2.2
- FreeSql 0.3.17
sqlSugarCore 4.9.9.3
sqlserver 14.00.1000 Express、mysql 5.6
测试项目
以 console 程序,创建步骤:
1、dotnet new console
2、dotnet add package FreeSql
3、dotnet add package sqlSugarCore
编码的过程
这个错误来自 sugar 创建数据库的时候,实体定义如下:
sugar的没有同步上来。
暂时先用 freesql 帮 sugar 创建了表。。。创建完后如下:
运行时又出现如下错误:
需要加一堆 IsIgnore
是的,还在报错,最终原因是我传入的 songs 是 IEnumerable
以 SqlServer 作为目录库,测试结果
以 MySql 作为目录库,测试结果
结束语
然而上面提到的批量更新,今天先到这吧。下次有兴致了再测试。
其他库我就不测试了,谢谢观看!请求献上宝贵的一星。
github:https://github.com/2881099/FreeSql
最终的测试代码
using FreeSql.DataAnnotations;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace orm_vs
{
class Program
{
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=20")
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=20")
.UseAutoSyncStructure(false)
.UseNoneCommandParameter(true)
//.UseConfigEntityFromDbFirst(true)
.Build();
static SqlSugarClient sugar {
get => new SqlSugarClient(new ConnectionConfig() {
//不欺负,让连接池100个最小
//ConnectionString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Min Pool Size=100;Max Pool Size=20",
//DbType = DbType.SqlServer,
ConnectionString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Min Pool Size=20;Max Pool Size=20",
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
}
static StringBuilder sb = new StringBuilder();
static void Main(string[] args) {
fsql.CodeFirst.SyncStructure(typeof(Song), typeof(Song_tag), typeof(Tag));
sugar.CodeFirst.InitTables(typeof(Song), typeof(Song_tag), typeof(Tag));
//sugar创建表失败:SqlSugar.SqlSugarException: Sequence contains no elements
//测试前清空数据
fsql.Delete<Song>().Where(a => a.Id > 0).ExecuteAffrows();
sugar.Deleteable<Song>().Where(a => a.Id > 0).ExecuteCommand();
Console.WriteLine("插入性能:");
Insert(1000, 1);
Console.Write(sb.ToString());
sb.Clear();
Insert(1000, 10);
Console.Write(sb.ToString());
sb.Clear();
Insert(1, 1000);
Console.Write(sb.ToString());
sb.Clear();
Insert(1, 10000);
Console.Write(sb.ToString());
sb.Clear();
Insert(1, 50000);
Console.Write(sb.ToString());
sb.Clear();
Console.WriteLine("查询性能:");
Select(1000, 1);
Console.Write(sb.ToString());
sb.Clear();
Select(1000, 10);
Console.Write(sb.ToString());
sb.Clear();
Select(1, 1000);
Console.Write(sb.ToString());
sb.Clear();
Select(1, 10000);
Console.Write(sb.ToString());
sb.Clear();
Select(1, 50000);
Console.Write(sb.ToString());
sb.Clear();
Select(1, 100000);
Console.Write(sb.ToString());
sb.Clear();
Console.Write(sb.ToString());
Console.WriteLine("测试结束,按任意键退出...");
Console.ReadKey();
}
static void Select(int forTime, int size) {
Stopwatch sw = new Stopwatch();
sw.Restart();
for (var a = 0; a < forTime; a++)
fsql.Select<Song>().Limit(size).ToList();
sw.Stop();
sb.AppendLine($"FreeSql Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
sw.Restart();
for (var a = 0; a < forTime; a++)
sugar.Queryable<Song>().Take(size).ToList();
sw.Stop();
sb.AppendLine($"SqlSugar Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms\r\n");
}
static void Insert(int forTime, int size) {
var songs = Enumerable.Range(0, size).Select(a => new Song {
Create_time = DateTime.Now,
Is_deleted = false,
Title = $"Insert_{a}",
Url = $"Url_{a}"
}).ToArray();
//预热
fsql.Insert(songs.First()).ExecuteAffrows();
sugar.Insertable(songs.First()).ExecuteCommand();
Stopwatch sw = new Stopwatch();
sw.Restart();
for (var a = 0; a < forTime; a++)
fsql.Insert(songs.AsEnumerable()).ExecuteAffrows();
sw.Stop();
sb.AppendLine($"FreeSql Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
sw.Restart();
for (var a = 0; a < forTime; a++)
sugar.Insertable(songs).ExecuteCommand();
sw.Stop();
sb.AppendLine($"SqlSugar Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms\r\n");
}
}
[Table(Name = "freesql_song")]
[SugarTable("sugar_song")]
public class Song {
[Column(IsIdentity = true)]
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public DateTime? Create_time { get; set; }
public bool? Is_deleted { get; set; }
public string Title { get; set; }
public string Url { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual ICollection<Tag> Tags { get; set; }
}
[Table(Name = "freesql_song_tag")]
[SugarTable("sugar_song_tag")]
public class Song_tag {
public int Song_id { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual Song Song { get; set; }
public int Tag_id { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual Tag Tag { get; set; }
}
[Table(Name = "freesql_tag")]
[SugarTable("sugar_tag")]
public class Tag {
[Column(IsIdentity = true)]
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public int? Parent_id { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual Tag Parent { get; set; }
public decimal? Ddd { get; set; }
public string Name { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual ICollection<Song> Songs { get; set; }
[SugarColumn(IsIgnore = true)]
public virtual ICollection<Tag> Tags { get; set; }
}
}
- 本地密码检索工具 – LaZagne Project
- 我是如何在SQLServer中处理每天四亿三千万记录的
- 程序猿是如何解决SQLServer占CPU100%的
- 记一次SQLServer的分页优化兼谈谈使用Row_Number()分页存在的问题
- 分享一个自制的 .net线程池1
- 分享一个自制的 .net线程池2
- 基于百度翻译的简单爬虫翻译-- coding:utf-8 --访问网址模拟浏览器创建文件夹用一个text文件保存,文件名用单词名字
- .net采集网页方法大全(5种)
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 中文分词之结巴分词~~~附使用场景+demo(net)
- 用微信二维码登录自己的网站
- 2620: [Usaco2012 Mar]Haybale Restacking
- 1671: [Usaco2005 Dec]Knights of Ni 骑士
- 1592: [Usaco2008 Feb]Making the Grade 路面修整
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- 一行能装逼的 JavaScript 代码
- python 技术篇-时间戳的获取,记录程序处理时间
- 基于SpringBoot AOP面向切面编程实现Redis分布式锁
- Python+Selenium 技巧篇-svg标签内元素的xpath定位方式
- 小书MybatisPlus第5篇-Active Record模式精讲
- Python 语法问题-module ‘pip._internal‘ has no attribute ‘pep425tags‘. 原因及解决办法,32位、64位查看pip支持万能方法
- 总在说 Spring Boot 内置了 Tomcat 启动,那它的原理你说的清楚吗?
- JavaScript 技巧篇-js增加延迟时间解决单击双击事件冲突,双击事件触发单击事件
- Python 技术篇-sha256()加密的使用方法,sha1、md5加密方法
- Python 技术篇-如何打印一段文字,用友云霸气控制台颜文字打印
- Python 技术篇-获取秒级时间戳、毫秒级时间戳
- Python 技术篇-基于随机数的uuid码的生成
- BAT 脚本技术-利用bat批处理脚本静态指定ip地址、自动获取ip地址设置
- Oracle 技巧篇-快速批量删除当前数据库连接的用户,一键清空所有session会话方法
- Spring Security 中如何细化权限粒度?