A library to measure your method, function execution time.
Project description
PY Profiler
A library to measure method, function or your restful api execution time.
Install
- Run
pip install py-profiler
orpip3 install py-profiler
to install this library
Usage
It comes with a really easy api to use, you can add profiler(name = None)
decorator to any method or function you want
to measure its execution time.
E.g:
from py_profiler import profiler, profiling_service
@profiler('hello')
def hello():
print('hello')
class Foo:
@profiler('Food.some_thing')
def some_thing(self):
print('some_thing')
# By default, profiler name is f'{class_name}.{method_name}'
@profiler()
def method_2(self):
print('method_2')
Access Profiler
- Exec time is in milliseconds
- View as a table
from py_profiler import profiling_service
print(profiling_service.as_table())
No | Name | Total Req | Pending Req | Total Exec Time | Last Exec Time | Highest Exec Time | Request Rate (req/sec) | Avg Time/Request (millis/req) |
---|---|---|---|---|---|---|---|---|
1 | Foo.method_2 | 1 | 0 | 0.014 | 0.014 | 0.014 | 71428.571 | 0.014 |
2 | Food.some_thing | 1 | 0 | 0.011 | 0.011 | 0.011 | 90909.091 | 0.011 |
3 | hello | 1 | 0 | 0.031 | 0.031 | 0.031 | 32258.065 | 0.031 |
- Integrate with Flask
- If you are using Flask to implement your Restful API. You can add
profiler_blueprint
to your Flash app.
E.g:
from flask import Flask
from waitress import serve
from py_profiler import profiler_blueprint
app = Flask(__name__)
app.register_blueprint(profiler_blueprint)
serve(
app,
host="0.0.0.0",
port=8080
)
Then you can access the profiler page at: http://127.0.0.1:8080/profiler
- Integrate with 3rd restful library.
You can build your custom profiler viewer by using as_html()
from py_profiler import profiling_service
html_page = profiling_service.as_html()
Then, you can implement a html page and return this html_page
to your client to see profiler viewer.
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
py_profiler-0.1.5.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file py_profiler-0.1.5.tar.gz
.
File metadata
- Download URL: py_profiler-0.1.5.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0fb4a6396bf863e17945db0d4997a342c8873baa4e9525170cefb7202c80392 |
|
MD5 | 4924885ee86f746fcbae7b1b3b6ad889 |
|
BLAKE2b-256 | aaf1fb0f3ea968572796b5b0a3750e7b7b9758744f38cfc0cd5211c6270893f1 |
File details
Details for the file py_profiler-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: py_profiler-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 757220faed7f3b1337eb9d73d48145b542b3d7faa53052481150aec74f765435 |
|
MD5 | a27d976f30ff54d5ba94b32517bfa168 |
|
BLAKE2b-256 | 97e4fd99df545ef5a3eacc0db7f604be1577c284856a6b8eed96fe2f78dbb831 |