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

Most people would agree that internationalizing an existing app is more expensive than developing
I am developing a generic layer that allows me to perform the basic save,
I am developing an application that needs to perform expensive calculations at start up.
Given an expensive function of n variables that returns a scalar value: f(x1, x2,
I just added some computationally expensive code to an Android game I am developing.
I'm working on developing a fairly robust 2D game engine as a base that
I am developing for a system that has an interactive telnet management console. Requirements
I'm developing a video game for the iPhone. I want each level to save
I am developing a rails app that allows users to post, much like facebook
I've been developing a piece of software that takes rules of the form 'A

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.