Measure CPU cycles from Python
Project description
Measure number of CPU cycles from Python
Mesures the number of cycles from start untill the end of the exectuion of a
code block. Corrects the measurement for the overhead for accessing the RDTSCP
.
Usage:
from cpu_measure import Measure
measure = Measure()
with measure:
find_kth_prime(k)
measure.cycles # Cycles taken
# 271828182845
with measure:
find_kth_prime(k + 1)
measure.cycles # Increments the counter
# 314159265358
Installation
pip intall cpu-measure
Details
The library uses RDTSCP
instruction to read the TSP register.
Note that the number of cycles is counted from the start utill the end
of the execution of the code block. One should be careful when interpreting
results of long-running tasks, especially that invlole IO. The current
thread can be put to sleep by the OS, and another thread may be scheduled.
In the meatime the TSP register will be being kept inctemented, and this will
be refleted in the measurement. For CPU bound tasks measruments are correct,
again, unless a thread has been rescheduled.
Building
Build requirements:
setuptools
Build with pip (installs build-time requirements automatically)
pip install .
Testing
The library must be built first.
python -m test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cpu_measure-0.0.2.tar.gz
.
File metadata
- Download URL: cpu_measure-0.0.2.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db53cc88c28ec78028562e4e825f2feb177c4d9e03206c50d563e293ea7ea228 |
|
MD5 | 06cb304d5be9eb05bd780f277a1a1e2e |
|
BLAKE2b-256 | c7697cdf5f639a41ffe86639e6027bb727325f8e15e136253406ba5f113fe115 |