protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(10000);//设置循环次数 using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { //ef using (WebTest.TestLib.SqlSugarTestEntities ef = new TestLib.SqlSugarTestEntities()) { pt.Execute(i => { var datas = ef.InsertTests.Where(c => c.id == 1 || c.id > 1000); foreach (var r in datas) { r.v1 = "new11"; r.v2 = "newv22"; r.v3 = "new33"; } ef.SaveChanges(); }, m => { }, "EF4.0+sql05 Linq语法"); } //ado.net pt.Execute(i => { db.ExecuteCommand(@" UPDATE InsertTest SET v1 =@v1 , v2 =@v2 , v3 =@v3 WHERE 1=1 and ((id =@id1) Or (id >@id1000))", new SqlParameter[] { new SqlParameter("@v1", "new11"), new SqlParameter("@v2", "new22"), new SqlParameter("@v3", "new33"), new SqlParameter("@id1", "1"), new SqlParameter("@id1000", "1000") }); }, m => { }, "ado.net"); //dapper var sqlConn = db.GetConnection(); pt.Execute(i => { sqlConn.Execute(@" UPDATE InsertTest SET v1 =@v1 , v2 =@v2 , v3 =@v3 WHERE 1=1 and ((id ='1') Or (id >'1000'))", new { v1 = "newv11", v2 = "newv22", v3 = "newv33", id1 = 1, id1000 = 1000 }); }, m => { }, "dapper"); //sqlSugar pt.Execute(i => { //更新10000次 db.Update <Models.InsertTest>(new { v1 = "newv11", v2 = "newv22", v3 = "newv33" }, it => it.id == 1 || it.id > 1000); }, m => { }, "sqlSugar"); } //输出测试页面 GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(10000); using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { //ado.GetDataTable pt.Execute(i => { db.GetDataTable(@"select * from (select s.*,row_number() over (order by s.id asc,s.name desc) r from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id where s.id>@id1 and s.id>@id2) t where t.r between @b and @e", new SqlParameter("@id1", "1"), new SqlParameter("@id2", "2"), new SqlParameter("@b", "11"), new SqlParameter("@e", "20")); }, m => { }, "ado.DateTable 纯SQL写法"); //dapper var conn = db.GetConnection(); pt.Execute(i => { conn.Query <Models.Student>(@"select * from (select s.*,row_number() over (order by s.id asc,s.name desc) r from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id where s.id>@id1 and s.id>@id2) t where t.r between @b and @e", new { id1 = 1, id2 = 2, b = 11, e = 20 }).ToList(); }, m => { }, "dapper 纯SQL写法"); //sqlSugar pt.Execute(i => { db.Sqlable().From("Student", "s") .Join("School", "sc", "sc.id", "s.sch_id", JoinType.INNER) .Join("subject", "sb", "sb.sid", "s.id", JoinType.LEFT).Where("s.id>@id1").Where("s.id>@id2") .SelectToPageList <Models.Student>("s.*", "s.id asc,s.name desc", 2, 10, new { id1 = 1, id2 = 2 }); }, m => { }, "sqlSugar SQL语法糖"); } using (WebTest.TestLib.SqlSugarTestEntities db = new TestLib.SqlSugarTestEntities()) { //EF pt.Execute(i => { var reval = (from s in db.Student join sc in db.School on s.sch_id equals sc.id join sb in db.Subject on s.id equals sb.sid into ssb from sb2 in ssb.DefaultIfEmpty() select new { s.id, s.name, s.sch_id, s.sex }).Where(c => c.id > 1).Where(c => c.id > 2).OrderBy(c => c.id).ThenByDescending(c => c.name).Skip(10).Take(10).ToList(); }, m => { }, "EF4.0+sql05 LINQ TO SQL"); } GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(1000); using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { //ado.GetDataTable pt.Execute(i => { db.GetDataTable(@"select * from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id"); }, m => { }, "ado.DateTable 纯SQL写法"); //dapper var conn = db.GetConnection(); pt.Execute(i => { conn.Query <Models.Student>(@"select * from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id").ToList(); }, m => { }, "dapper 纯SQL写法"); //sqlSugar pt.Execute(i => { db.Sqlable().Form("Student", "s") .Join("School", "sc", "sc.id", "s.sch_id", JoinType.INNER) .Join("subject", "sb", "sb.sid", "s.id", JoinType.LEFT).SelectToList <Models.Student>("*"); }, m => { }, "sqlSugar SQL语法糖"); //sqlSugar pt.Execute(i => { db.SqlQuery <Models.Student>(@"select * from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id").ToList(); }, m => { }, "sqlSugar 纯SQL写法"); } using (WebTest.TestLib.SqlSugarTestEntities db = new TestLib.SqlSugarTestEntities()) { //EF pt.Execute(i => { db.ExecuteStoreQuery <WebTest.TestLib.Student>(@"select * from dbo.Student s inner join dbo.School sc on sc.id=s.sch_id left join dbo.Subject sb on sb.sid=s.id"); }, m => { }, "EF4.0+sql05 纯SQL写法"); } GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(10000); int id = 1; using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { //ado.GetDataTable pt.Execute(i => { db.GetDataTable("select * from Student WHERE ID>@id", new SqlParameter("@id", id)); }, m => { }, "ado.DateTable 纯SQL写法"); //dapper var conn = db.GetConnection(); pt.Execute(i => { conn.Query <Models.Student>("select * from Student where id>@id", new { id = id }).ToList(); }, m => { }, "dapper 纯SQL写法"); //sqlSugar pt.Execute(i => { db.Queryable <Models.Student>().Where(c => c.id == id).ToList(); }, m => { }, "sqlSugar 拉姆达"); } using (WebTest.TestLib.SqlSugarTestEntities db = new TestLib.SqlSugarTestEntities()) { //EF pt.Execute(i => { db.Student.Where(c => c.id == id).ToList(); }, m => { }, "EF4.0+sql05 拉姆达"); } GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(1100);//设置循环次数 using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { TuncateTable(db); AddTest(pt, db); //sqlSugar pt.Execute(i => { db.Delete <Models.InsertTest>(it => it.id == i); }, m => { }, "sqlSugar"); TuncateTable(db); AddTest(pt, db); //ado.net pt.Execute(i => { db.ExecuteCommand("delete InsertTest where id=@id", new SqlParameter("@id", i)); }, m => { }, "ado.net"); TuncateTable(db); AddTest(pt, db); //dapper pt.Execute(i => { db.GetConnection().Execute("delete InsertTest where id=@id", new { id = i }); }, m => { }, "dapper"); } //输出测试页面 GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(10000); using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { //ado.GetDataTable pt.Execute(i => { db.GetDataTable("select * from(select *,row_number() over(order by id) as r from Student where id>@id) t where t.r between @b and @e", new SqlParameter("@id", "0"), new SqlParameter("@b", 11), new SqlParameter("@e", 20)); }, m => { }, "ado.DateTable 纯SQL写法"); //dapper var conn = db.GetConnection(); pt.Execute(i => { conn.Query <Models.Student>("select * from(select *,row_number() over(order by id) as r from Student where id>@id) t where t.r between @b and @e", new { id = 0, b = 11, e = 20 }).ToList(); }, m => { }, "dapper 纯SQL写法"); //sqlSugar pt.Execute(i => { db.Queryable <Models.Student>().Where(c => c.id > 0).OrderBy("id").ToPageList(2, 10); }, m => { }, "sqlSugar 拉姆达"); } using (WebTest.TestLib.SqlSugarTestEntities db = new TestLib.SqlSugarTestEntities()) { //EF pt.Execute(i => { db.Student.Where(c => c.id == 2).OrderBy(c => c.id).Skip(10).Take(10).ToList(); }, m => { }, "EF4.0+sql05 拉姆达"); } GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest p = new PerformanceTest(); p.SetCount(10000 * 100); //循环次数(默认:1) p.SetIsMultithread(false); //是否启动多线程测试 (默认:false) p.Execute( i => { Response.Write(i); // }, message => { //输出总共运行时间 Response.Write(message); //总共执行时间:1.02206秒 } ); Gridview1.DataSource = p.GetChartSource(); Gridview1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(100000);//设置循环次数 Models.Student ss = new Models.Student() { id = 1 }; pt.Execute(i => { ResolveExpress r = new ResolveExpress(); Expression <Func <Models.InsertTest, bool> > func = x => x.id > ss.id; r.ResolveExpression(r, func); }, m => { }, "lambda"); //输出测试页面 GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }
protected void Page_Load(object sender, EventArgs e) { PerformanceTest pt = new PerformanceTest(); pt.SetCount(10000);//设置循环次数 using (SqlSugarClient db = new SqlSugarClient(System.Configuration.ConfigurationManager.ConnectionStrings["sqlConn"].ToString())) { var sqlconn = db.GetConnection(); TuncateTable(db);//清空 //sqlSuagr pt.Execute(i => { db.Insert <Models.InsertTest>(GetData()); }, m => { }, "sqlSuagr"); TuncateTable(db); //ef4.0+Sql05 using (TestLib.SqlSugarTestEntities ef = new TestLib.SqlSugarTestEntities()) { pt.Execute(i => { ef.InsertTests.AddObject(GetEFData()); ef.SaveChanges(); }, m => { }, "ef4.0+Sql05"); } TuncateTable(db); //dapper pt.Execute(i => { sqlconn.Execute("insert into InsertTest (v1,v2,v3,int1,d1,txt ) values(@v1,@v2,@v3,@int1,@d1,@txt);select @@identity;", GetData()); }, m => { }, "dapper"); TuncateTable(db); //ado.net pt.Execute(i => { db.GetScalar("insert into InsertTest (v1,v2,v3,int1,d1,txt ) values(@v1,@v2,@v3,@int1,@d1,@txt);select @@identity;", new SqlParameter[] { new SqlParameter("@d1", DateTime.Now), new SqlParameter("@int1", 11), new SqlParameter("@txt", "哈另一个txt"), new SqlParameter("@v1", "v1sdfasdas"), new SqlParameter("@v2", "v2sdfasfas"), new SqlParameter("@v3", "v3adfasdf"), new SqlParameter("@id", 1) }); }, m => { }, "ado.net"); } //输出测试页面 GridView gv = new GridView(); gv.DataSource = pt.GetChartSource(); gv.DataBind(); Form.Controls.Add(gv); }