Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ExecTiming
#1
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

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]
[Image: zR2d6mM.png]
Reply
#2
It looks great!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020