Python Forum

Full Version: Time in microseconds seems to update only every millisecond
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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,
The image I get from your code doesn't look like what I expected from your description
[Image: Figure-1.png]
I think (do a search to verify for yourself) that a Microsoft OS can only do milliseconds. Linux and Mac will do microseconds.
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/tim...platforms/ suggests there is indeed a Windows issue involved here.

Thanks,