# Most accurate python code timer function?

**URL:** <https://forum.inductiveautomation.com/t/most-accurate-python-code-timer-function/39987>\
**Category:** General Discussion\
**Created:** [October 24, 2020, 10:05pm UTC](https://forum.inductiveautomation.com/t/most-accurate-python-code-timer-function/39987 "2020-10-24T22:05:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [October 24, 2020, 10:05pm UTC](https://forum.inductiveautomation.com/t/most-accurate-python-code-timer-function/39987/1 "2020-10-24T22:05:37Z")

</div>

What’s the most accurate python timer function that can be used, in my case, for Windows platforms? For example; time.time(), time.clock(), java.lang.System.nanoTime(), datetime.now() ~ .microsecond, timeit, etc…?

I would like to to be precise at least to the millisecond, but after reading some on this, there can be certain factors that would make one function over the other not as precise in Windows opposed to Unix.

I’m basically wanting to get the most precise time possible that it takes a piece of code to execute (it can go fast, hence why I want it to the millisecond or better).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2020, 1:03am UTC](https://forum.inductiveautomation.com/t/most-accurate-python-code-timer-function/39987/2 "2020-10-25T01:03:22Z")

</div>

System.nanoTime() is the most precise, and is the only one of the above that is guaranteed to be monotonic.
