Skip to main content

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 Benchmark and execTimeList decorator at the same time on one object as the decorator replace the function name by timed.
  • Recursive tracked functions are not supported. If a function decorated with @execTimeList calls 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_duration and total time stay correct; only the exclusive-time views (pie chart, timeline) are affected.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gtimeit-0.0.6.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gtimeit-0.0.6-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

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

Hashes for gtimeit-0.0.6.tar.gz
Algorithm Hash digest
SHA256 0c89545195481e43783887ba3a575e84a5a2dffb31bdf6b386d1f5d772878deb
MD5 7c99710b97c2db3e7130f8d2728808ec
BLAKE2b-256 e98aa2d72ba303e9c1fdfd8e97a5dc0d3b6d96b1b34be6acd92f61295a97d885

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtimeit-0.0.6.tar.gz:

Publisher: publish.yml on Chthi/gtimeit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for gtimeit-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 177a2d054e493b5d6b236da6ed27503aac9c9aab239ae318f443677f0e7fce67
MD5 835db44b7e81b48a29084283f24ca9a6
BLAKE2b-256 0d5cd70b629bc36f9fbe501bf1828e1944fd4b89bb78762efa312444ebc07f9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtimeit-0.0.6-py3-none-any.whl:

Publisher: publish.yml on Chthi/gtimeit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page