Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpu_measure-0.0.2.tar.gz (2.8 kB view details)

Uploaded Source

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

Hashes for cpu_measure-0.0.2.tar.gz
Algorithm Hash digest
SHA256 db53cc88c28ec78028562e4e825f2feb177c4d9e03206c50d563e293ea7ea228
MD5 06cb304d5be9eb05bd780f277a1a1e2e
BLAKE2b-256 c7697cdf5f639a41ffe86639e6027bb727325f8e15e136253406ba5f113fe115

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page