|
-
Jul 14th, 2005, 07:18 AM
#1
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?
- ØØ -
-
Jul 14th, 2005, 12:42 PM
#2
Sleep mode
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.
-
Jul 15th, 2005, 02:12 AM
#3
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.
- ØØ -
-
Jul 15th, 2005, 05:50 AM
#4
-
Jul 15th, 2005, 06:40 AM
#5
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.
- ØØ -
-
Jul 15th, 2005, 06:57 AM
#6
Sleep mode
Re: High precision timer.
I didn't think that through .
Last edited by Pirate; Jul 15th, 2005 at 07:35 AM.
-
Jul 15th, 2005, 07:05 AM
#7
Re: High precision timer.
Ummm..sorry...is that an expression? I didn't get it. Sorry. Can you repeat it with other words..
-
Jul 15th, 2005, 07:36 AM
#8
Sleep mode
Re: High precision timer.
lol , wrong word in a wrong window (fixed) .I was typing in different windows .
.
.
-
Jul 15th, 2005, 08:07 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|