Not Logged In

big_O 0.7

big_O is a Python module to estimate the time complexity of Python code from
its execution time. You can use it to analyze how your functions scale
with inputs of increasing size.

big_O executes a Python function for input of increasing size N, and measures
its execution time. From the measurements, big_O fits a set of time complexity
classes and returns the best fitting class. This is an empirical way to
compute the asymptotic class of a function in “Big-O”. notation. (Strictly
speaking, we’re empirically computing the Big Theta class.)

Usage

For concreteness, let’s say we would like to compute the asymptotic behavior
of a simple function that finds the maximum element in a list of positive
integers:

big_o inferred that the asymptotic behavior of the find_max fuction is
linear, and returns an object containing the fitted coefficients for the
complexity class. The second return argument, others, contains a dictionary
of all fitted classes with the residuals from the fit as keys:

Submodules

big_o.datagen: this sub-module contains common data generators, including an identity generator that simply returns N (datagen.n_), and a data generator that returns a list of random integers of length N (datagen.integers).

big_o.complexities: this sub-module defines the complexity classes to be fit to the execution times. Unless you want to define new classes, you don’t need to worry about it.