在编写完成一个程序后,你们都比较关心程序的性能如何,想把程序优化得更好。不少时候凭我的直觉来优化程序是件很是不靠普的事情,即便你是一个优秀的开人员也很难准确地判断程序中那些出现问题。VS2010提供了性能分析工具就能轻松地帮咱们解决这一事情。web
class Program
{
static List<Expression> mExpressions = new List<Expression>();
static Random mRan = new Random();
static void Main(string[] args)
{
try
{
string dbpath = @"Data Source=d:\\northwind.db;Pooling=true;FailIfMissing=false;";
DBContext.SetConnectionDriver<SqliteDriver>(ConnectionType.Context1);
DBContext.SetConnectionString(ConnectionType.Context1, dbpath);
mExpressions.Add(Order.shipCountry == "Switzerland");
mExpressions.Add(Order.shipRegion == "RJ");
mExpressions.Add(Order.customerID.In(Customer.customerID, Customer.country == "UK"));
mExpressions.Add(Order.customerID.In(Customer.customerID, Customer.country == "Germany"));
mExpressions.Add(Order.orderDate > "1997-8-5");
mExpressions.Add(Order.orderDate < "1997-12-1");
mExpressions.Add(Order.orderDate > "1997-5-1" & Order.orderDate<"1997-11-5");
System.Threading.Thread thread;
for (int i = 0; i < 10; i++)
{
thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Test
));
thread.Start();
}
}
catch (Exception e_)
{
Console.WriteLine(e_.Message);
}
}
static void Test(object obj)
{
while (true)
{
Expression exp = mExpressions[mRan.Next(mExpressions.Count - 1)];
Console.WriteLine(exp.Count<Order>());
System.Threading.Thread.Sleep(mRan.Next(50, 5000));
}
}
}
到了这里发现原来是connection.Open方法占用了大部分资源,这个时候就想到这个测试程序跑这么久为何链接打开这么损耗资源,是否是链接池没有开启致使每次操做都进行数据库链接操做呢?数据库
其实VS2010给咱们提供的分析工具真得很轻松就可让咱们了解到程序代码情况,从而优化程序的代码。若是有这烦脑的朋友不防试下:)dom