Metadata-Version: 2.4
Name: gtimeit
Version: 0.0.6
Summary: Timer, benchmark and resource usage tracker. A tool for python functions. Time and compare your functions inside or outside a program.
Author: Thibault Charmet
License: MIT
Project-URL: Homepage, https://github.com/Chthi/gtimeit
Keywords: time,benchmark,track,plot,compare
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 3 - Alpha
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.18.2
Provides-Extra: plot
Requires-Dist: matplotlib>=3.2.1; extra == "plot"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# 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.
```bash
# 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](https://docs.python.org/2/library/timeit.html) 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.

<img src="images/benchmark_graph.png" width="" height=""/>

<img src="images/benchmark_legend.png" width="" height=""/>

<img src="images/benchmark_terminal.png" width="" height=""/>


#### 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.

<img src="images/tracker_pie.png" width="" height=""/>

<img src="images/tracker_history.png" width="" height=""/>

<img src="images/tracker_terminal.png" width="" height=""/>

#### 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.

