Question

When I call cProfile.run('myFunction1') it returns with a number of function calls.

I would like to compare various versions of myFunction and find the most effective one(e.g. with the least complexity).

What is the connection between the function calls and the complexity?

What do the function calls describe?

If I have two functions, is the function with the least number of function calls the most efficient?

Was it helpful?

Solution

The number of function calls is exactly what is means: number of (sub-)function calls. There's no strict correlation between func calls and complexity. To find the most efficient implementation you should try mapping your function against different argument sets and timing it. Using the timeit module.

Calculating the complexity of a function is a too wide argument for a single answer. It depends on the algorithm itself and the complexity of the subfunctions it calls.

Here for more: https://en.wikipedia.org/wiki/Analysis_of_algorithms

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top