2

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?

4

1 回答 1

1

函数调用的数量正是它的意思:(子)函数调用的数量。func 调用和复杂性之间没有严格的相关性。要找到最有效的实现,您应该尝试将您的函数映射到不同的参数集并对其进行计时。使用timeit模块。

计算函数的复杂性对于单一答案来说是一个过于宽泛的论据。这取决于算法本身和它调用的子函数的复杂性。

在这里了解更多:https ://en.wikipedia.org/wiki/Analysis_of_algorithms

于 2013-07-29T08:37:27.247 回答