Python的timeit模块用于计数代码片段执行的时长。
1.timeit模块的组成
- class Timer(stmt="pass", setup="pass", timer=time.perf_counter, globals=None)
设置globals=globals(),Python标准库中的内置函数globals(),返回一个字典对象,其中包含当前模块中定义的全局符号
- def timeit(stmt="pass", setup="pass", timer=time.perf_counter, number=1000000, globals=None)
- def repeat(stmt="pass", setup="pass", timer=time.perf_counter, repeat=3, number=1000000, globals=None)
python -m timeit [-n an_integer] [-r an_integer] [-u U] [-s S] [-t] [-c] [-h] [statement ...]
参数说明:
- -n N, --number=