Accurate speed profiler for Python code using perf_counter.
Project description
speed-profiler
Accurate speed profiler for Python code using perf_counter.
This module is for finding bottlenecks in Python code. The first call to the module
initializes it with a name to identify the profile. Following that are calls to mark()
for timing purposes. Here's an example (Also in the demo folder):
Installation
pip install speed-profiler
Usage
from speed_profiler import SpeedProfiler
from time import sleep
from pprint import pprint
sp = SpeedProfiler('Sleep Tester')
def foo():
sleep(0.2)
sp.mark('Foo')
def bar():
sleep(0.1)
sp.mark('bar')
def baz():
foo()
bar()
sp.mark('baz')
profile = sp.stop()
pprint(profile)
baz()
Output:
[{'duration': 0.20027251401916146,
'identifier': 'Sleep Tester',
'line_num': 5,
'percent_time': 66.66},
{'duration': 0.10016519500641152,
'identifier': 'Foo',
'line_num': 10,
'percent_time': 33.34},
{'duration': 1.0420975740998983e-05,
'identifier': 'bar',
'line_num': 15,
'percent_time': 0.0},
{'duration': 9.390001650899649e-06,
'identifier': 'baz',
'line_num': 21,
'percent_time': 0.0}]
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
speed-profiler-0.0.4.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for speed_profiler-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02f99adf688fd1adb7597fbb9e55e90bb41235f5d2e18fce17338a9f93dd691f |
|
MD5 | 151a893291ab9d1b9c0c772ffdd96925 |
|
BLAKE2b-256 | deade8c10e3c1447c3ca65b4134b5c138a7fde4887048c288ef7345192bb9389 |