https://github.com/zariiii9003/win-precise-time
https://github.com/zariiii9003/win-precise-time
getsystemtimepreciseasfiletime precise python sleep
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zariiii9003/win-precise-time
- Owner: zariiii9003
- License: mit
- Created: 2022-06-06T19:44:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T18:03:17.000Z (over 1 year ago)
- Last Synced: 2025-03-23T14:17:45.558Z (11 months ago)
- Topics: getsystemtimepreciseasfiletime, precise, python, sleep
- Language: C
- Homepage:
- Size: 38.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# win-precise-time
[](https://pypi.org/project/win-precise-time)
[](https://pypi.org/project/win-precise-time)
[](https://win-precise-time.readthedocs.io/en/latest/?badge=latest)
The documentation is available [here](https://win-precise-time.readthedocs.io/en/latest/).
-----
**Table of Contents**
- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [Test](#test)
- [Build](#build)
- [License](#license)
## Description
On Windows the builtin `time.time()` provides a timestamp with ~15ms resolution.
This package provides the function `win_precise_time.time()` to retrieve an accurate timestamp by using
[GetSystemTimePreciseAsFileTime](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime).
The function is implemented as a C extension so the performance is equal to the builtin `time.perf_counter()`
(both functions rely on [QueryPerformanceCounter](https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter)).
The function `win_precise_time.sleep()` reimplements the more precise `time.sleep()` version of CPython >= 3.11 for older python versions.
This enables sub-millisecond sleep precision without increasing the Windows timer resolution via [timeBeginPeriod](https://docs.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timebeginperiod).
## Installation
```console
pip install win-precise-time
```
## Usage
```python-repl
>>> import win_precise_time as wpt
>>> wpt.time() # retrieve current time
1654539449.4548845
>>> wpt.sleep(0.001) # sleep for 1ms
```
## Test
```console
pip install tox
tox
```
## Build
```console
pip install build
python -m build .
```
## License
`win-precise-time` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.