System.Data.EntityClient.EntityConnection conn = null;
public void testc()
{
if(conn==null)
{string connold = "Data Source=.;Initial Catalog=KM;User ID=sa;Password=sasa";
string connstr = "metadata=res://*/;provider=System.Data.SqlClient;provider connection string='" + connold + "'";
conn= new System.Data.EntityClient.EntityConnection(connstr);
}
DateTime dt1 = DateTime.Now;
for (int i = 0; i < 100000; i++)
{
using (KMEntities kme = new KMEntities(conn))
{
}
}
DateTime dt2 = DateTime.Now;
var span = dt2 - dt1;
string 总毫秒数 = span.TotalMilliseconds.ToString();
}
测试四次:分别为
8765 |
7750 |
7750 |
7937 |
平均每次8050毫秒
8050/100000=0.08 毫秒
CPU使用率会明显增高 50% 左右
但如果只循环1000次,只增高10左右