Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MuckRock/cpuprofile
A simple Python package to profile CPU speed by computing the Fibonacci sequence
https://github.com/MuckRock/cpuprofile
Last synced: 28 days ago
JSON representation
A simple Python package to profile CPU speed by computing the Fibonacci sequence
- Host: GitHub
- URL: https://github.com/MuckRock/cpuprofile
- Owner: MuckRock
- License: mit
- Created: 2019-05-09T15:57:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-09T17:15:28.000Z (over 5 years ago)
- Last Synced: 2024-07-05T23:09:05.089Z (6 months ago)
- Language: Python
- Size: 2.93 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CPU Profile
This is a simple package to measure CPU speed by calculating the time it takes to
compute Fibonacci numbers. It is useful in contexts where CPU speed is unknown or can
fluctuate, such as cloud function environments, and can serve as a rough measure of how
long subsequent compute-intensive code will take to run.## Installation
```sh
pip install cpuprofile
```## Usage
```python
from cpuprofile import profile_cpu# Calculate the CPU speed by computing Fibonacci numbers.
elapsed_time = profile_cpu()
# elapsed_time is ~0.18 (seconds) on a 2.5 GHz Intel Core i7 2015 Macbook Pro.
# Or, a number can be specified to calculate the nth Fibonacci (default: 28).
elapsed_time = profile_cpu(15) # 15th Fibonacci; takes around 0.0006 seconds
elapsed_time = profile_cpu(35) # 35th Fibonacci; takes about 5 seconds
```## Credit
The minimalist approach of recursively calculating Fibonacci numbers as a way to profile
the CPU is inspired by:- Booth, J. (2015).
[Not so incognito: Exploiting resource-based side channels in javascript engines](http://jombooth.com/static/thesis.pdf)
(Undergraduate thesis, Harvard University).