Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3480964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:24:06+00:00 2026-05-18T10:24:06+00:00

I need an Http request that I can use in .Net which takes under

  • 0

I need an Http request that I can use in .Net which takes under 100 ms. I’m able to achieve this in my browser so I really don’t see why this is such a problem in code.

I’ve tried WinHTTP as well as WebRequest.Create and both of them are over 500ms which isn’t acceptable for my use case.

Here are examples of the simple test I’m trying to pass. (WinHttpFetcher is a simple wrapper I wrote but it does the most trivial example of a Get Request that I’m not sure it’s worth pasting.)

I’m getting acceptable results with LibCurlNet but if there are simultaneous usages of the class I get an access violation. Also since it’s not managed code and has to be copied to bin directory, it’s not ideal to deploy with my open source project.

Any ideas of another implementation to try?

    [Test]
    public void WinHttp_Should_Get_Html_Quickly()
    {
        var fetcher = new WinHttpFetcher();
        var startTime = DateTime.Now;          
        var result = fetcher.Fetch(new Uri("http://localhost"));
        var endTime = DateTime.Now;
        Assert.Less((endTime - startTime).TotalMilliseconds, 100);
    }
    [Test]
    public void WebRequest_Should_Get_Html_Quickly()
    {
        var startTime = DateTime.Now;
        var req = (HttpWebRequest) WebRequest.Create("http://localhost");
        var response = req.GetResponse();
        var endTime = DateTime.Now;
        Assert.Less((endTime - startTime).TotalMilliseconds, 100);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:24:07+00:00Added an answer on May 18, 2026 at 10:24 am

    When benchmarking, it is best to discard at least the first two timings as they are likely to skew the results:

    • Timing 1: Dominated by JIT overhead i.e. the process of turning byte code into native code.
    • Timing 2: A possible optimization pass for the JIT’d code.

    Timings after this will reflect repeat performance much better.

    The following is an example of a test harness that will automatically disregard JIT and optimization passes, and run a test a set number of iterations before taking an average to assert performance. As you can see the JIT pass takes a substantial amount of time.

    JIT:410.79ms

    Optimize:0.98ms.

    Average over 10 iterations:0.38ms

    Code:

    [Test]
    public void WebRequest_Should_Get_Html_Quickly()
    {
        private const int TestIterations = 10;
        private const int MaxMilliseconds = 100;
    
        Action test = () =>
        {
           WebRequest.Create("http://localhost/iisstart.htm").GetResponse();
        };
    
        AssertTimedTest(TestIterations, MaxMilliseconds, test);
    }
    
    private static void AssertTimedTest(int iterations, int maxMs, Action test)
    {
        double jit = Execute(test); //disregard jit pass
        Console.WriteLine("JIT:{0:F2}ms.", jit);
    
        double optimize = Execute(test); //disregard optimize pass
        Console.WriteLine("Optimize:{0:F2}ms.", optimize);
    
        double totalElapsed = 0;
        for (int i = 0; i < iterations; i++) totalElapsed += Execute(test);
    
        double averageMs = (totalElapsed / iterations);
        Console.WriteLine("Average:{0:F2}ms.", averageMs);
        Assert.Less(averageMs, maxMs, "Average elapsed test time.");
    }
    
    private static double Execute(Action action)
    {
        Stopwatch stopwatch = Stopwatch.StartNew();
        action();
        return stopwatch.Elapsed.TotalMilliseconds;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I find out the http request my python cgi received? I need
I need to write a python script that makes multiple HTTP requests to the
I need loging all HTTP request (from any application). I have Delphi 7.0. Anybody
I need to determine whether an HTTP request was an HTTP/1.0 or an HTTP/1.1
I need to set time out for the Http Request we make to a
I need to send a http post request from my android device to a
I need a transformation of the following working curl command: curl --data-binary @data.txt http://www.example.com/request.asp
I need to monitor HTTP traffic in my dev env which is PHP/Apache/Windows. But
I have a .NET Windows Service which spawns a thread that basically just acts
I'm running this application on a server that has assigned 5 IPs. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.