Jun-05-2019, 07:47 PM
Several years ago, I wrote a small module named PyTimer that provided some features to make it easier to determine the execution time of functions and sections of code. Today, I am posting about an updated version of it called ExecTiming. The example below highlights some neat features like being able to decorate functions, time existing functions, use functions to randomize argument values during timing, plot collected data, and determine best fit curves. ExecTiming uses numpy, scipy, and scikit-learn for determining the best fit curve, and matplotlib for graphing. However, text output features are available even if those packages can't be imported.
PyPI
GitHub
Wiki
![[Image: cJ62w1Z.png]](https://i.imgur.com/cJ62w1Z.png)
![[Image: zR2d6mM.png]](https://i.imgur.com/zR2d6mM.png)
PyPI
GitHub
Wiki
from exectiming.exectiming import Timer timer = Timer() @timer.decorate(runs=10, log_arguments=True, call_callable_args=True) def bubble_sort(array): while True: switched = False for i in range(0, len(array)-1): if array[i] > array[i+1]: array[i], array[i+1] = array[i+1], array[i] switched = True if not switched: break return array bubble_sort(lambda: [randint(0, 100) for _ in range(randint(100, 2500))]) curve = timer.best_fit_curve(transformers={0: len}) timer.plot(transformer=len, plot_curve=True, curve=curve, x_label="List Length") timer.time_it(sorted, lambda: [randint(0, 100) for _ in range(randint(100, 2500))], call_callable_args=True, runs=10, log_arguments=True) curve = timer.best_fit_curve(transformers={0: len}) timer.plot(transformer=len, plot_curve=True, curve=curve, x_label="List Length")
![[Image: cJ62w1Z.png]](https://i.imgur.com/cJ62w1Z.png)
![[Image: zR2d6mM.png]](https://i.imgur.com/zR2d6mM.png)