Python Forum
Time in microseconds seems to update only every millisecond - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Time in microseconds seems to update only every millisecond (/thread-16823.html)



Time in microseconds seems to update only every millisecond - markB - Mar-16-2019

Hi all,

I'm trying to time part of a code on microsecond level.
Code below shows the idea.
Result is however that the stored value on changes once every 1000 steps, I Would have expected an continuously increment of the stored value.

Must be something I'm not seeing here, can anyone assist?
from datetime import datetime
import matplotlib.pyplot as plt

log =[]
a=datetime.now().microsecond
for i in range(10000):
    b=datetime.now().microsecond
    log.append(b-a)
    
plt.plot(log)  
Thanks,


RE: Time in microseconds seems to update only every millisecond - micseydel - Mar-16-2019

The image I get from your code doesn't look like what I expected from your description
[Image: Figure-1.png]


RE: Time in microseconds seems to update only every millisecond - woooee - Mar-16-2019

I think (do a search to verify for yourself) that a Microsoft OS can only do milliseconds. Linux and Mac will do microseconds.


RE: Time in microseconds seems to update only every millisecond - markB - Mar-16-2019

Thanks for the replies,

The posted figure is indeed completely different from mine, I get a step function out of it.
https://www.expobrain.net/2013/07/12/timestamp-and-microseconds-on-windows-platforms/ suggests there is indeed a Windows issue involved here.

Thanks,