I'm making my own HTTPWebRequest class and I'm trying to optimize the time it takes to read the buffer and make a request, so far it takes around 800-1000ms for every request to google.com
Same code in C++ takes ~ 200ms any suggestions how I could optimize this better?
public class OWebReq
{
public string LastError;
public bool LastOK = false;
public OWebReq()
{
}
public static void Init()
{
ServicePointManager.Expect100Continue = false;
ServicePointManager.DefaultConnectionLimit = 9999;
WebRequest.DefaultWebProxy = (WebProxy)null;
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
}
public string GET(string url, WebProxy proxy = null)
{
LastOK = false;
var req = (HttpWebRequest)WebRequest.Create(url);
req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36";
req.Proxy = proxy;
req.KeepAlive = false;
req.Timeout = 5000;
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
try
{
using(var response=(HttpWebResponse)req.GetResponse())
{
var responseStream = response.GetResponseStream();
if(responseStream!=null)
{
using (var sr = new StreamReader(responseStream))
{
return sr.ReadToEnd();
}
}
}
}
catch (Exception ex)
{
LastError = ex.Message;
return null;
}
return null;
}
}
Executing code till var response=(HttpWebResponse)req.GetResponse()
takes ~ 350ms