Hello everybody! I'm trying to produce a timestamp (system time) in windows (Python 2.7) with resolution equal to or better than microseconds. Calling time.time() repeatedly in a loop it appears it only updates in approximately 0.01 second increments. Using datetime.datetime.today() seems to show similar results. Anybody have a possible way of getting a better timestamp?

Thanks in advance!

Recommended Answers

All 6 Replies

time.clock() gives more accurate time in Windows.

It has better resolution as a timer but it doesn't give you the system time. If I could get time.clock's resolution in a timestamp I would be happy. I was considering trying to use time.clock in combination with one of the system time's to try and improve the system time resolution but not sure where to start.

Maybe you coul do own format string for today datetime object.

It's not a problem to display more precision in the timestamp. Both of the methods I mentioned above show high precision (datetime object has microsecond attribute), but if you call it many times in a loop you will see it only updates that value every 0.01 seconds making it a lot of useless precision. I need a high resolution timer coupled with the timestamp so I can actually compare timestamps at the microsecond level.

It looks like calling the windows API QueryPerformanceCounter() and QueryPerformanceFrequency() functions is what I am looking for, if I can tie it in to the actual time:


I'm thinking I will try to zero my precise timer with the system time updates so I can count time with ticks.

Thanks for the responses pyTony. Any ideas would still be appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.