• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

性能测试之如何获取网页相应时间

发布: 2009-4-17 10:01 | 作者: 不详 | 来源: 测试时代采编 | 查看: 282次 | 进入软件测试论坛讨论

领测软件测试网

    request.CookieContainer = cc;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            Stream requestStream = request.GetRequestStream();
            byte[] byteArray = Encoding.UTF8.GetBytes(data);
            requestStream.Write(byteArray, 0, byteArray.Length);
            requestStream.Close();
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Uri responseUri = response.ResponseUri;
            Stream receiveStream = response.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            StreamReader readStream = new StreamReader(receiveStream, encode);
            string result = readStream.ReadToEnd();
            info = result;
            return 0;

        }
        public static bool GetBool(string html)
        {

            Regex regtable = new Regex(@"http://img.dotad.net/lg.gif", RegexOptions.Singleline);
            Match ma = regtable.Match(html);
            if (ma.Success)
            {
                return true;
            }
            else
                return false;
        }

        public static void ThreadProc()
        {

            string info = "";
            string data = "";
            string url = "http://203.86.46.53/lg/index.aspx";
            long i=0;
            HiPerfTimer pt = new HiPerfTimer();     // create a new PerfTimer object
            pt.Start();                             // start the timer
            while (i++<100)
            {
              
                PostData(url, data, out info);
                //System.Console.WriteLine(info);
                if (GetBool(info) == true)
                {
                    rt++;                  
                }
                else
                {
                    wr++;                  
                }             
             }
             pt.Stop();
             System.Console.WriteLine("成功" + rt + " 次,失败  " + wr + " 次\n");
             Console.WriteLine("用时: {0} sec\n",
                  pt.Duration); // print the duration of the timed code
        }

        static void Main(string[] args)
        {
                 
         
            Console.WriteLine("Test\n");            // the code to be timed                                
           

            long j = 0;
            while(j++<15)
            {
              Thread t = new Thread(new ThreadStart(ThreadProc));
              t.Start();
            
            }
          
        }
    }
}

 

 

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

22/2<12

关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网