Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <% Validator.RenderClient(Response.Output); %>
- <% Validator.RenderClient(); %>
- 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]));
- HttpContext.Current=0,536ms, Local variable=0,486ms, R=110,2%
- public static HttpContext get_Current()
- {
- return (ContextBase.Current as HttpContext);
- }
- public static object HostContext
- {
- get
- {
- object hostContext =
- Thread.CurrentThread.GetIllogicalCallContext().HostContext;
- if (hostContext == null)
- {
- hostContext = GetLogicalCallContext().HostContext;
- }
- return hostContext;
- }
- System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch();
- // With HttpContext.Current:
- sp.Start();
- for (int i = 0; i < 100; i++)
- {
- HttpContext.Current.Response.Output.Write(i.ToString());
- }
- sp.Stop();
- long result1 = sp.ElapsedTicks;
- // Without:
- TextWriter output2 = HttpContext.Current.Response.Output;
- sp.Reset();
- sp.Start();
- for (int i = 0; i < 100; i++)
- {
- output2.Write(i.ToString());
- }
- sp.Stop();
- long result2 = sp.ElapsedTicks;
Add Comment
Please, Sign In to add comment