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

  • SEARCH
  • Home
  • 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 529249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:04:19+00:00 2026-05-13T09:04:19+00:00

Is it expensive? I am developing an HtmlHelper that renders directly to Response.Output in

  • 0

Is it expensive?

I am developing an HtmlHelper that renders directly to Response.Output in order to save unnecesary string creation and I need to choose between:

<% Validator.RenderClient(Response.Output); %>

and

<% Validator.RenderClient(); %>

and get the textWriter from HttpContext.Current.Response

  • 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-13T09:04:19+00:00Added an answer on May 13, 2026 at 9:04 am

    @Dawkins

    100 runs is too few, you need to run about 10000 times several times and repeat it and then take the average of that to get a reliable result. The margin of error is to big in your example, but it’s the right way to go.

    Here’s what i did:

    var results1 = new List<long>();
    var results2 = new List<long>();
    
    for (int j = 0; j < 100; j++)
    {
        var sp = new System.Diagnostics.Stopwatch();
    
        // With HttpContext.Current: 
        sp.Start();
        for (int i = 0; i < 10000; i++)
        {
            HttpContext.Current.Response.Output.Write(i);
        }
        sp.Stop();
    
        results1.Add(sp.ElapsedTicks);
    
        // Without: 
        TextWriter output2 = HttpContext.Current.Response.Output;
        sp.Reset();
    
        sp.Start();
        for (int i = 0; i < 10000; i++)
        {
            output2.Write(i);
        }
        sp.Stop();
    
        HttpContext.Current.Response.Clear();
    
        results2.Add(sp.ElapsedTicks);
    }
    
    results1.Sort();
    results2.Sort();
    
    HttpContext.Current.Response.Write(string.Format("HttpContext.Current={0:0.000}ms, Local variable={1:0.000}ms, R={2:0.0%}<br/>", results1[results1.Count / 2] / (double)TimeSpan.TicksPerMillisecond, results2[results2.Count / 2] / (double)TimeSpan.TicksPerMillisecond, (double)results1[results1.Count / 2] / (double)results2[results2.Count / 2]));
    

    Your result show that there’s a 18% performance difference, which shows that it’s more expensive but it off by 8%.

    I re-ran the numbers several times and came up with a 10% difference with a error margin of less then 1%.

    It stablaizes around:

    HttpContext.Current=0,536ms, Local variable=0,486ms, R=110,2% 
    

    Anyway, HttpContext.Current to pose a significant performance problem you’ll need to call it way more than 10000 per request (the cost is largely made up by the Response.Write calls). And that’s likely not going to happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks something like this: word big expensive smart fast
I feel that using GetEnumerator() and casting IEnumerator.Current is expensive. Any better suggestions? I'm
How expensive is it to perform the dereference operation on a pointer? I can
I have a fairly expensive array calculation (SpectralResponse) which I like to keep to
Source RegexOptions.IgnoreCase is more expensive than I would have thought (eg, should be barely
I'm wondering, how expensive it is to have many threads in waiting state in
The activity monitor in sql2k8 allows us to see the most expensive queries. Ok,
I have a class in which looking up an instance is expensive, so instances
I'm using DRb within a Rails application to offload an expensive task outside the
In general, how expensive is locking in Java? Specifically in my case: I have

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.