The standard time.time() function provides sub-second precision, though that precision varies by platform. For Linux and Mac precision is +- 1 microsecond or 0.001 milliseconds. Python on Windows with Python < 3.7 uses +- 16 milliseconds precision due to clock implementation problems due to process interrupts. The timeit module can provide higher resolution if you're measuring execution time.

>>> import time
>>> time.time()        #return seconds from epoch
1261367718.971009      

Python 3.7 introduces new functions to the time module that provide higher resolution for longer time periods:

>>> import time
>>> time.time_ns()
1530228533161016309
>>> time.time_ns() / (10 ** 9) # convert to floating-point seconds
1530228544.0792289
Answer from daf on Stack Overflow
🌐
Python.org
discuss.python.org β€Ί async-sig
Higher resolution timers on Windows? - Async-SIG - Discussions on Python.org
June 1, 2022 - Hello, sorry if I don’t use precise terminology, I am new to asyncio. Is there a way to have the asyncio runner to use higher resolution timers on Windows? I have a process that interfaces with some hardware. It needs to poll some status at a regular interval (of the order of a second), and ...
Discussions

how does the timeit library get such high precision?
the clock function described there is ancient and part of the "needs to work anywhere" aspect of vanilla C. If you do not require such compatibility, on linux there is clock_gettime which can be combined with CLOCK_MONOTONIC or CLOCK_REALTIME. These clocks on modern linux have much, much higher precision than 10ms. There are analogs to these routines and constants on other platforms. time.perf_counter uses CLOCK_MONOTONIC. See here The other factor is averaging; timeit runs your code multiple times and measures the larger interval. If I do X 1000 times and each time takes 1ns, it is much easier to measure 1us than it is 1ns. More on reddit.com
🌐 r/Python
14
23
May 10, 2023
Been stuck on a piece of code for a MS accurate timer that goes months+. If power is lost, it needs to accurately pick up the schedule again.

How do you guarantee that your reference crystal doesn't drift? The answer is you can't. There is no way to do this with a regular computer - if you want millisecond accuracy over months, you need an external clock reference.

Your best bet is an embedded solution. For something reasonably self contained do a search on "GPS disciplined oscillators", which is the kind of territory you're looking at.

Unless I'm missing something in the spec?

Maybe you mean that you need to know exactly where in the cycle you are; as long as the timer is regular, it surely shouldn't be too difficult. Wouldn't you just save the start time exactly and then do a time calculation? It's "just" some modulo arithmetic then surely, assuming you can get the real time to within a certain tolerance.

Let's say your cycle is 1800ms, as in the example above. Isn't it a matter of working out how many of those there are in a day for example, then finding the remainder. Once you have that, add up number of days between the saved time and now, multiply by the remainders between the last start time and now, And then work out the residual number of cycles to account for time of day differences. You don't need to add them all up.

More on reddit.com
🌐 r/AskProgramming
16
13
February 12, 2024
Is there a more accurate thing than time.sleep?

It's not python, it's your OS. When you call time.sleep() python just passes the request along to your OS. For most OS's timing like that is pretty loose; Β± 2-5 ms is completely acceptable. You need a "real time OS" if you need super accurate timing.

More on reddit.com
🌐 r/learnpython
2
7
October 22, 2017
More accurate function then time.sleep?
Have you considered simply checking the current time in a loop until it's what you want? More on reddit.com
🌐 r/learnpython
8
1
August 6, 2023
🌐
Real Python
realpython.com β€Ί python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. (Source) First, you’ll use perf_counter() to create a Python timer.
🌐
TutorialsPoint
tutorialspoint.com β€Ί How-to-measure-time-with-high-precision-in-Python
How to measure time with high-precision in Python?
June 3, 2025 - The time.perf_counter() function is used to measure short durations. It provides the highest available resolution timer and also includes time elapsed even when the local system is in sleep.
🌐
PyPI
pypi.org β€Ί project β€Ί win-precise-time
win-precise-time Β· PyPI
Tags Windows , time , sleep , GetSystemTimePreciseAsFileTime , SetWaitableTimerEx , CREATE_WAITABLE_TIMER_HIGH_RESOLUTION Β· Requires: Python >=3.7 Β· Development Status Β· 5 - Production/Stable Β· Programming Language Β· Python Β· Python :: 3 Β· Python :: Implementation :: CPython Β·
      Β» pip install win-precise-time
    
Published Β  Oct 08, 2023
Version Β  1.4.2
🌐
GitHub
github.com β€Ί nw2s β€Ί precision-timer-python
GitHub - nw2s/precision-timer-python: OS X support for precision timers and Linux support for high-resolution timers in C and python Β· GitHub
Provides an interval-based, high precision timer in C and python assuming your kernel has compiled support. These libraries do not require the process to have elevated priveliges.
Author Β  nw2s
🌐
GitHub
github.com β€Ί belm0 β€Ί perf-timer
GitHub - belm0/perf-timer: An indispensable performance timer for Python
Following the semantics of the various performance counters in Python's time module, trio_perf_counter() provides high resolution measurement of a Trio task's execution time, excluding periods where it's sleeping or blocked on I/O. (TrioPerfTimer ...
Starred by 24 users
Forked by 4 users
Languages Β  Python 98.7% | Makefile 1.3% | Python 98.7% | Makefile 1.3%
Find elsewhere
🌐
DaniWeb
daniweb.com β€Ί programming β€Ί software-development β€Ί code β€Ί 465991 β€Ί high-resolution-time-measurement-python
High resolution time measurement (Python) | DaniWeb
October 23, 2013 - ''' time_high_resolution_counter.py measure elapsed time of a Python calculation time.perf_counter() is new in Python 3.3 ''' import time # returned value is in fractional seconds start = time.perf_counter() # let's time this calculation y = ...
🌐
YouTube
youtube.com β€Ί codedash
python high precision timer - YouTube
Instantly Download or Run the code at https://codegive.com title: python high precision timer tutorial with code examplesintroduction:in python, measuring t...
Published Β  February 22, 2024
Views Β  57
🌐
Python
python-list.python.narkive.com β€Ί mRxEWfDk β€Ί high-resolution-timers
High-resolution timers
import time time.time() 1011195116.002301 It gives me microsecond precision, and for that I am grateful. But the Use time.clock() - it will always provide the best timer for the platform. The profiler uses this, and it needs the best precision it can get. Python on Windows uses the high-performance counter exposed by the Windows API for excellent resolution.
🌐
LinuxQuestions.org
linuxquestions.org β€Ί questions β€Ί programming-9 β€Ί high-resolution-timers-in-python-923479
High resolution timers in python?
I'm brand new to python and am trying out how to do some of the real basic things I've been doing in perl for years. one of those is the ability to
🌐
Reddit
reddit.com β€Ί r/python β€Ί how does the timeit library get such high precision?
r/Python on Reddit: how does the timeit library get such high precision?
May 10, 2023 -

it seems that C can get about a 10millisecond precision. (https://stackoverflow.com/questions/5248915/execution-time-of-c-program)

but when I had a look at (https://docs.python.org/3/library/timeit.html) it can give outputs like

0.19665591977536678

How is this possible? I am actually looking to time functions in C (I want to generate a report on how much faster is C than python in various usecases) so, I want to measure the time for executing a function in C with extremely high precision, is that even possible?

🌐
Built In
builtin.com β€Ί articles β€Ί timing-functions-python
Timing Functions in Python: A Guide | Built In
There are four common methods to time a function in Python, including: time.perf_counter(), time.time(), timeit and cprofile or profile. Let’s look at each one. The time.perf_counter() function is a high-resolution timing function that uses ...
🌐
ZetCode
zetcode.com β€Ί python β€Ί time-perf_counter
Python time.perf_counter Function - Complete Guide
April 11, 2025 - The time.perf_counter function returns a high-resolution performance counter value in fractional seconds. It's designed for measuring short durations. Key characteristics: highest available timer resolution, monotonic (always increases), not affected by system clock changes, and ideal for ...
🌐
GitHub
github.com β€Ί morefigs β€Ί interval-timer
GitHub - morefigs/interval-timer: interval-timer is a Python package that enables iterating over a sequence of regular time intervals with high precision. Β· GitHub
interval-timer is a Python package that enables iterating over a sequence of regular time intervals with high precision. - morefigs/interval-timer
Author Β  morefigs
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί time-perf_counter-function-in-python
time.perf_counter() function in Python - GeeksforGeeks
January 13, 2026 - The time.perf_counter() function returns a high-resolution timer value used to measure how long a piece of code takes to run.
🌐
PyPI
pypi.org β€Ί project β€Ί wres
wres Β· PyPI
β”‚ β”‚ optional arguments: β”‚ -h, --help show this help message and exit β”‚ -s RESOLUTION, --set RESOLUTION β”‚ set resolution in 100-ns units β”‚ --setmax set maximum resolution β”‚ --setmin set minimum resolution β”‚ -v, --version show version └──── 1.4 details ─────────── 1.4.1 `set_resolution' β•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œβ•Œ Set resolution of system timer.
      Β» pip install wres
    
Published Β  Feb 05, 2017
Version Β  1.0.3
🌐
PyPI
pypi.org β€Ί project β€Ί elapsedtimer
elapsedtimer Β· PyPI
Python elapsed time utilities. The main interface to this package is an ElapsedTimer class. This class will use the highest resolution timer available to Python depending on the OS, either time.time() or time.clock(). Its purpose is easily to ...
      Β» pip install elapsedtimer
    
Published Β  Mar 30, 2022
Version Β  1.0.0
🌐
GitHub
gist.github.com β€Ί sandos β€Ί 7b1947c4d636142a36bd2c0c004c36e8
Max timer resolution windows from python Β· GitHub
Max timer resolution windows from python. GitHub Gist: instantly share code, notes, and snippets.