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 425195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:21:19+00:00 2026-05-12T19:21:19+00:00

I have a normal asp.net page containing some code that I want to measure

  • 0

I have a normal asp.net page containing some code that I want to measure the execution time of. I have created a very basic helper class for this purpose:

public class Timing
{
    private long m_ticksBefore;
    private long m_ticksAfter;

    public void Before()
    {
        m_ticksBefore = DateTime.Now.Ticks;
    }

    public void After()
    {
        m_ticksAfter = DateTime.Now.Ticks;
    }

    public void TraceTime(string note)
    {
        TimeSpan span = new TimeSpan(m_ticksAfter - m_ticksBefore);
        System.Diagnostics.Trace.Write(string.Format("\n...Timing for {0}...\nTicks: \t{1}\nMilliseconds: \t{2}\nSeconds: \t{3}\n..................", note, span.Ticks, span.TotalMilliseconds, span.TotalSeconds));
    }
}

I instantiate a new Timing object and wrap the code I wish to monitor with the Before() and After methods and finally call the TraceTime() method in order to output the result to the output window in the IDE.

The strange thing is that the first request to the page results in an expected timing result of some 40 milliseconds, but refreshing the page (F5) gives me 0 ticks of execution time. Even executing the page with new parameters forcing the execution of different code within the monitored area reveals a flat 0.

If I use System.Diagnostics.StopWatch instead I get much more realistic results

Stopwatch watch1 = Stopwatch.StartNew();
//Some code to monitor
watch1.Stop();
System.Diagnostics.Trace.Write(watch1.ElapsedTicks);

To me the code seems very similar and I cannot seem to find out why the first approach fails to output realistic results…

It seems to be some sort of optimization issue that is performed behind the scene, but I don’t really get it. Maybe it is due to my personal Timing issue i.e. bed-time issue…

  • 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-12T19:21:19+00:00Added an answer on May 12, 2026 at 7:21 pm

    Although DateTime.Now appears to have a resolution of 100ns, Windows actually only updates its internal clock every 15ms. Therefore, if your code takes less than about 7.5ms to run, it will appear to have taken no time at all, since on average you have to wait 7.5ms for DateTime.Now to change.

    If you need more accurate timing, you can (as you’ve found) use StopWatch. This uses a different, more accurate API to get results.

    EDIT The MSDN documentation for DateTime.Now gives the resolution as “approximately 10ms”. The GetTickCount API (which uses the same system timer) gives its resolution as “typically in the range of 10 milliseconds to 16 milliseconds”.

    Apparently it’s hardware dependent – single processor systems are typically 10ms, multiple processor systems are typically 15ms.

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

Sidebar

Ask A Question

Stats

  • Questions 334k
  • Answers 334k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can assign an empty context menu to the controls… May 14, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer Now I feel stupid: all it took was seeing my… May 14, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer You could pass an additional parameter to the current page's… May 14, 2026 at 3:20 am

Related Questions

I'm building UI logging into a long-existing ASP.NET enterprise application. I have my own
I have a normal asp.net combobox on my web page. The current version is
I use SubSonic 3.0.0.3 ActiveRecord with ASP.NET MVC and it is very nice. However,
I have an ASP.NET page that is taking too long to load. A little

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.