函数计时器
Project description
计时器-zyf_timer
安装
pip install zyf_timer
使用
示例1:timeit
from zyf_timer import timeit
@timeit
def sleep(seconds: int):
time.sleep(seconds)
运行
>> sleep(1)
Function sleep -> takes 1.001 seconds
示例2:repeat_timeit
from zyf_timer import repeat_timeit
@repeat_timeit(number=5)
def list_insert_time_test():
l = []
for i in range(10000):
l.insert(0, i)
@repeat_timeit(repeat=3, number=5)
def list_append_time_test():
l = []
for i in range(1000000):
l.append(i)
return l
@repeat_timeit(number=5, print_detail=True)
def list_gen_time_test():
l = [i for i in range(1000000)]
return l
@repeat_timeit(repeat=3, number=5, print_detail=True)
def list_extend_time_test():
l = []
for i in range(1000000):
l.extend([i])
@repeat_timeit(repeat=3, number=5, print_detail=True, print_table=True)
def list_range_time_test():
l = list(range(1000000))
运行
>> list_insert_time_test()
average 0.098 seconds
>> list_append_time_test()
average trial 2.326 seconds. average function call 0.465 seconds
>> list_gen_time_test()
Time Spend of 5 function calls:
Function -> list_gen_time_test: total 1.445 seconds, average 0.289 seconds
Average: 0.289 seconds
>> list_extend_time_test()
Time Spend of 3 trials with 5 function calls per trial:
Function -> list_extend_time_test:
best: 3.303 seconds, worst: 3.787 seconds, average: 3.617 seconds
Average trial: 3.617 seconds. Average function call: 0.723 seconds
>> list_range_time_test()
Time Spend of 3 trials with 5 function calls per trial:
+----------------------+---------------+---------------+---------------+-----------------------+
| Function | Best trial | Worst trial | Average trial | Average function call |
+----------------------+---------------+---------------+---------------+-----------------------+
| list_range_time_test | 0.620 seconds | 0.644 seconds | 0.629 seconds | 0.126 seconds |
+----------------------+---------------+---------------+---------------+-----------------------+
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zyf_timer-1.3.tar.gz
(3.1 kB
view hashes)