用法一:

import timeit

start_time = timeit.default_timer()
func1()
print(timeit.default_timer() - start_time)

用法二:

import timeit

time_function = 'func1(arg1)'
time_setup = 'from __main__ import arg1'
t = timeit.Timer(time_function, time_setup)
print(t.timeit(1))


time_function = 'func1(arg1)'
time_setup = 'from __main__ import arg1'
print(timeit.timeit(time_function, setup=time_setup, number = 1))

发表评论

电子邮件地址不会被公开。 必填项已用*标注