数据访问效率测试

发表于:2011-7-01 10:14

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:深蓝医生    来源:51Testing软件测试网采编

分享:

  根据这个功能,写了一个.net控制台程序来测试,测试程序没有使用任何数据访问框架,直接使用ADO.NET,下面是多线程测试的代码,其它代码略:

  1. public static void Test2(string connName1,string connName2)  
  2.        {  
  3.            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();  
  4.            watch.Start();  
  5.            string allJjdmList = "";  
  6.            string connString = getConnectionString();  
  7.            //SqlConnection conn = new SqlConnection(connString);  
  8.            //conn.Open();  
  9.  
  10.            string sql = "select jjdm from [FundYield] group by jjdm order by jjdm asc";  
  11.            DataSet ds = getData(connString, sql);  
  12.            int allCount = ds.Tables[0].Rows.Count;  
  13.            int p = (int)(allCount * 0.5);  
  14.  
  15.            System.Threading.Thread t1=new System.Threading.Thread (new System.Threading.ParameterizedThreadStart (tp1=>  
  16.                {  
  17.                    for (int i = 0; i < p; i++)  
  18.                    {  
  19.                        string jjdm = ds.Tables[0].Rows[i][0].ToString();  
  20.  
  21.                        object result = getSclar(ConfigurationManager.ConnectionStrings[connName1].ConnectionString,  
  22.                       string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));  
  23.                        if (result != DBNull.Value)  
  24.                        {  
  25.                            DateTime dt = Convert.ToDateTime(result);  
  26.                            //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);  
  27.                        }  
  28.  
  29.                        allJjdmList = allJjdmList + "," + jjdm;  
  30.                    }  
  31.  
  32.                    Console.WriteLine("Tread 1 used all time is(ms):{0}", watch.ElapsedMilliseconds);  
  33.                }  
  34.            ));  
  35.  
  36.            System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(tp2 =>  
  37.            {  
  38.                for (int i = p; i < allCount; i++)  
  39.                {  
  40.                    string jjdm = ds.Tables[0].Rows[i][0].ToString();  
  41.                    //这里不论使用default还是express,区别不大  
  42.                    object result = getSclar(ConfigurationManager.ConnectionStrings[connName2].ConnectionString,  
  43.                        string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));  
  44.                    if (result != DBNull.Value)  
  45.                    {  
  46.                        DateTime dt = Convert.ToDateTime(result);  
  47.                        //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);  
  48.                    }  
  49.                      
  50.                    allJjdmList = allJjdmList + "," + jjdm;  
  51.                }  
  52.  
  53.                Console.WriteLine("Tread 2 used all time is(ms):{0}", watch.ElapsedMilliseconds);  
  54.            }  
  55.            ));  
  56.  
  57.            t1.Start();  
  58.            t2.Start();  
  59.            t1.Join();  
  60.            t2.Join();  
  61.  
  62.            Console.WriteLine("====All thread completed!========");  
  63.  
  64.        }

42/4<1234>
春暖花开更文季,点击参与还有惊喜礼品~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海漕溪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号