Results 1 to 9 of 9

Thread: High precision timer.

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    High precision timer.

    Is there a high precision timer in .NET at all? I have tested the System.DateTime structure on my Linux machine, and it seems pretty fast to me...unless I am getting to tired and have an error in my code:

    Please tell me if you see a logic error. Since I am pretty tired now...
    Code:
            long diff = 0;
            long totdiff = 0;
            System.DateTime dt1 = System.DateTime.Now;
            System.DateTime dt2 = System.DateTime.Now;
            
            for (int i = 0; i < 10000; i++){
            
               dt1 = System.DateTime.Now;
               diff = dt1.Ticks - dt2.Ticks;
               dt2 = dt1;
               totdiff += diff;
               //Console.WriteLine("Tid" + i + ": " + diff);
               
            }
            
            totdiff /= 10000;
            
            Console.WriteLine("Total diff: " + totdiff);
    This gives me a resolution from 0.04-0.09ms on my computer, witch is surprisingly good. But I read an article that a MVP wrote, that it seldoms gives you better resolution then 16ms. Something I can't see right now. Is that because it it on Windows is wrapped around timeGetTime or GetTickCount API or what? Can anyone test what they get on their Win machine, and or find the error in my test?


    - ØØ -

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: High precision timer.

    I found a class shipped with VS.NET sdk examples that claims it has the best timer resolution but I can't remember specifically what was it .You might need to look at it.

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: High precision timer.

    Well, I am sitting in Linux these days. So I guess I will have problems with finding that one. At least this week. But if anyone else have seen it or remember what class or what ever it uses, I will be pretty interested in it.


    - ØØ -

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Ok , I found the snippet code .It consists mainly of two classes :
    1-HighResolutionTimeSpan
    2-PerformanceTimer

    , I will post the two classes used in a class called "Display" . Tell us the results as MS developers are depending on these two classes clearly .
    Attached Files Attached Files
    • File Type: cs ci.cs (2.7 KB, 93 views)

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: High precision timer.

    Ohhh yeah...it is using the Querry performance API. That is not .NET, and will no way be cross platformed. I have all ready wrapped up (or rather ported my C++ timer)QuerryPerformanceFrec/Counter into a class. But that is not going to cut it for cross platform development. Only Win.


    - ØØ -

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: High precision timer.

    I didn't think that through .
    Last edited by Pirate; Jul 15th, 2005 at 07:35 AM.

  7. #7

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: High precision timer.

    Ummm..sorry...is that an expression? I didn't get it. Sorry. Can you repeat it with other words..

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: High precision timer.

    lol , wrong word in a wrong window (fixed) .I was typing in different windows .
    .
    .

  9. #9

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: High precision timer.

    Ohh....I thought my English was getting even worse then it used to...


    Well I guess I have to keep on searching, or at least get the code tested on Windows, so I can see if it is only Linux it performs that good.


    - ØØ -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width