Using Python’s “timeit” Module to Benchmark Functions Directly (Instead of Passing in a String to be Executed)
All the basic examples for Python's timeit module show strings being executed. This lead to, in my opinion, somewhat convoluted code such as:
#! /usr/bin/env python
import timeit
def f():
pass
if __name__ == "__main__":
timer = timeit.Timer("__main__.f()", "import __main__")
result = timer.repeat(repeat=100, number=100000)
print("{:8.6f}".format(min(result)))
For some reason, the fact that you can call a function directly is only (again, in my opinion) obscurely Read more [...]