性能测试之如何获取网页相应时间
前一段时间,为了测试的需要,需要编写一个多线程的程序,就是最大限度的访问某个网页上认证标签,以获得大概该认证标签每秒钟能响应多少次,于是搜索了一些网上的资料,于是编写了下面的这个程序,虽然这个程序不是我们使用的最终版本,但是也反映了测试的思想,大家略微进行改造,就可以用于类似的测试。 using System;
using System.Net;
using System.IO;
using System.Threading;
using System.Timers;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace TestUrl
{ internal class HiPerfTimer
{
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(
out long lpPerformanceCount); [DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(
out long lpFrequency); private long startTime, stopTime;
private long freq; // Constructor
public HiPerfTimer()
{
startTime = 0;
stopTime = 0; if (QueryPerformanceFrequency(out freq) == false)
{
// high-performance counter not supported
throw new Win32Exception();
}
} // Start the timer
public void Start()
{
// lets do the waiting threads there work
Thread.Sleep(0); QueryPerformanceCounter(out startTime);
} // Stop the timer
public void Stop()
{
QueryPerformanceCounter(out stopTime);
} // Returns the duration of the timer (in seconds)
public double Duration
{
get
{
return (double)(stopTime - startTime) / (double)freq;
}
}
} class Program
{ static long rt = 0;
static long wr = 0; public static int PostData(string url, string data, out string info)
{ info = "";
CookieContainer cc = new CookieContainer();
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/