摘要:LINQ To SQL 的性能 (列出部分的测试程序)
一时兴起,测了一下LINQ To SQL的性能,
?以100000笔数据的读入来测试,为求平衡,特别以5次读取之总值测试.
读取方式 | 结果 |
With Un-Typed DataTable Load (use DataAdapter without Delete/Insert/Update assocation) | 5188 ms |
With LINQ To SQL???????????????????????????????????????????????????????????????????? | 4203 ms |
我很讶异LINQ To SQL的性能,居然呈现出比Un-Typed DataTable更快,虽然就理论上而言,
LINQ To SQL所产生的类于成本上应比DataRow来得低,但这样的差距能引起我的怀疑,
或许我尚有遗漏之处也说不定,待较有空时,审视一下LINQ To SQL的Fill机制,应能找到其
性能提升的证据.
列出部分测试的程序.
With UnTyped DataTable
static void TestUnTypedLoad()
?{
??????????? SqlConnection conn = new SqlConnection(DSPerformanceTest.Properties.Settings.Default.Northwind2ConnectionString);
??????????? DataTable table = new DataTable();
??????????? using (conn)
??????????? {
??????????????? using(SqlCommand cmd = new SqlCommand("SELECT * FROM TEST_TABLE",conn))
??????????????? {
??????????????????? using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
??????????????????? {???????????????????????
??????????????????????? adapter.Fill(table);
??????????????????? }
??????????????? }
??????????? }???????????
??????? }
With LINQ to SQL
static void TestLoadWithLinq()
?{???????????
??????????? NorthwindDataContext context = new NorthwindDataContext();
??????????? var s = (from s1 in context.TEST_TABLEs select s1).ToList();
}
原文:大专栏 LINQ To SQL 的性能 (列出部分的测试程序)
原文地址:https://www.cnblogs.com/chinatrump/p/11513164.html