Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azrafe7/simpleprofiler
A simpler profiler for Python functions.
https://github.com/azrafe7/simpleprofiler
Last synced: 11 days ago
JSON representation
A simpler profiler for Python functions.
- Host: GitHub
- URL: https://github.com/azrafe7/simpleprofiler
- Owner: azrafe7
- Created: 2013-05-02T20:18:06.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-05-02T20:49:12.000Z (over 11 years ago)
- Last Synced: 2024-11-05T13:22:15.671Z (about 2 months ago)
- Language: Python
- Size: 109 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SimpleProfiler
==============A simpler profiler for Python functions.
Description
-----------
It works as a function decorator and writes out simple stats on standard output when the program terminates.Usage
-----------
Import `profile` from `SimpleProfiler` and use it to decorate the functions that you want to profile/time.Example
-----------test.py:
from SimpleProfiler import profile
ITERATIONS = 100000
@profile
def doSomething():
for _ in range(ITERATIONS):
pass
@profile
def doMath(x):
sum = 0
for i in range(ITERATIONS):
sum += x * x * i
return sum
def notProfiled(x, y):
sum = 0
for _ in range(ITERATIONS):
sum += x * y
return sum
if __name__ == "__main__":
for _ in range(10):
doSomething()
notProfiled(123, 456)
notProfiled(321, 0)
doMath(3)
doMath(7**7)
doSomething()
doMath(666)
Output:name calls total_time average_time
---- ----- ---------- ------------
doSomething 20 0.2290 0.0115
doMath 30 2.7212 0.0907PS: Change `range` to `xrange` in the test with Python < 3.0.