Timer, benchmark and resource usage tracker. A tool for python functions. Time and compare your functions inside or outside a program.
Project description
gtimeit
Graphical code timer, and function time usage tracker. A tool for python functions. Time and compare your functions inside or outside a program.
Installation
Installing as library
The easiest way is to use pip.
# install the library with plotting capabilities (requires matplotlib)
pip install gtimeit[plot]
# or without
pip install gtimeit
You can now import the tools in your code.
from gtimeit import Benchmark
from gtimeit import execTimeList, display_performances
Installing for developpement
Or you can install from Github.
git clone https://github.com/Chthi/gtimeit
cd gtimeit
pip install --editable ".[plot,dev]"
Benchmark
Allows to run multiple python functions a certain amount of times and to compare there respective execution times. Similar to timeit Display curves of all the execution times. Prototype : benchmarking for complexity tests up to one variable parameter. The variable take all the values of a given range and the benchmarck keeps track of the executions times.
Usage :
bm = Benchmark()
bm.add(fct1, *args, **kwargs)
bm.add(fct2, *args, **kwargs)
bm.add(fctn, *args, **kwargs)
bm.run(20, multiplicator=100)
Quick usage :
bm = Benchmark([fct1, fct2], 300)
Examples
More examples available in benchmark_examples.py.
def plusEgale(i=1):
i += 1
return i
def plusPuisEgale(i=1):
i = i + 1
return i
# running 200 tests 100000 times each
bm = Benchmark()
bm.add(plusEgale, 42)
bm.add(plusPuisEgale, 42)
bm.run(200, multiplicator=100000)
# short version for procedures
bm = Benchmark([plusEgale, plusPuisEgale], 200, multiplicator=100000)
Tracker
Allow to keep track of the execution time of some functions in a program. Useful to know which part of your program take the more time to execute.
Usage
Use the decorator @execTimeList before every function you want to keep track of.
The execution time of a function is defined by the total execution time of the code and of the functions called inside that are not taged with @execTimeList.
Use display_performances() to display the results.
Examples
from gtimeit import execTimeList, display_performances
@execTimeList
def additions():
i = 0
for x in range(1,100000):
i += 1
@execTimeList
def sumrange():
sum(range(1,100000))
@execTimeList
def extending():
l = []
for x in range(1,100000):
l.extend([0])
@execTimeList
def fct1():
extending()
sumrange()
# simulate some basic code
for x in range(4):
additions()
sumrange()
extending()
for x in range(2):
sumrange()
extending()
for x in range(10):
additions()
fct1()
display_performances()
Limitations
For the current version :
- It is not possible to use
BenchmarkandexecTimeListdecorator at the same time on one object as the decorator replace the function name bytimed. - Recursive tracked functions are not supported. If a function decorated with
@execTimeListcalls itself (directly or through mutual recursion) on the same thread, its exclusive time is misattributed: the accumulated durations all collapse onto the innermost call while the outer frames are left at zero. The number of calls,wall_durationand total time stay correct; only the exclusive-time views (pie chart, timeline) are affected.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gtimeit-0.0.6.tar.gz.
File metadata
- Download URL: gtimeit-0.0.6.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c89545195481e43783887ba3a575e84a5a2dffb31bdf6b386d1f5d772878deb
|
|
| MD5 |
7c99710b97c2db3e7130f8d2728808ec
|
|
| BLAKE2b-256 |
e98aa2d72ba303e9c1fdfd8e97a5dc0d3b6d96b1b34be6acd92f61295a97d885
|
Provenance
The following attestation bundles were made for gtimeit-0.0.6.tar.gz:
Publisher:
publish.yml on Chthi/gtimeit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gtimeit-0.0.6.tar.gz -
Subject digest:
0c89545195481e43783887ba3a575e84a5a2dffb31bdf6b386d1f5d772878deb - Sigstore transparency entry: 1861216359
- Sigstore integration time:
-
Permalink:
Chthi/gtimeit@fa85a4c1d1710d1a0c1fb92f7988dcf7754fcd07 -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/Chthi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa85a4c1d1710d1a0c1fb92f7988dcf7754fcd07 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gtimeit-0.0.6-py3-none-any.whl.
File metadata
- Download URL: gtimeit-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
177a2d054e493b5d6b236da6ed27503aac9c9aab239ae318f443677f0e7fce67
|
|
| MD5 |
835db44b7e81b48a29084283f24ca9a6
|
|
| BLAKE2b-256 |
0d5cd70b629bc36f9fbe501bf1828e1944fd4b89bb78762efa312444ebc07f9e
|
Provenance
The following attestation bundles were made for gtimeit-0.0.6-py3-none-any.whl:
Publisher:
publish.yml on Chthi/gtimeit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gtimeit-0.0.6-py3-none-any.whl -
Subject digest:
177a2d054e493b5d6b236da6ed27503aac9c9aab239ae318f443677f0e7fce67 - Sigstore transparency entry: 1861216453
- Sigstore integration time:
-
Permalink:
Chthi/gtimeit@fa85a4c1d1710d1a0c1fb92f7988dcf7754fcd07 -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/Chthi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa85a4c1d1710d1a0c1fb92f7988dcf7754fcd07 -
Trigger Event:
release
-
Statement type: