Hitdongfeng 发表于 2018-9-25 10:52:05

{:10_243:}

777psp 发表于 2018-9-25 22:51:26

支持,支持

qianmoney 发表于 2018-9-26 10:11:46

666

apbxh 发表于 2018-9-26 19:41:20

{:5_106:}{:5_109:}

笨笨龙123 发表于 2018-9-27 15:58:33

1

dtspsppt 发表于 2018-9-27 16:13:05

我看看!!

dsx-123 发表于 2018-9-27 21:33:46

学习学习

张丫彦丫楚 发表于 2018-9-29 13:46:06

>>> import timeit
>>> import timeit
>>> timeit.timeit('"-".join(str(n) for n in range(100))',number=10000)
0.22145586600001366
>>> timeit.timeit('"-".join(str(n) for n in range(100))',number=100000)
2.19172915499999
>>> timeit.timeit('a = "-".join(str(n) for n in range(100))',number=10000)
0.22280868299998247
>>> timeit.timeit('a = "-".join(str(n) for n in range(100));return a',number=10000)
>>> timeit.timeit('a = "-".join(str(n) for n in range(100))',repeat=3,number=10000)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
    timeit.timeit('a = "-".join(str(n) for n in range(100))',repeat=3,number=10000)
TypeError: timeit() got an unexpected keyword argument 'repeat'
>>> timeit.repeat('a = "-".join(str(n) for n in range(100))',repeat=3,number=10000)

>>> timeit.repeat('a = "-".join(str(n) for n in range(100))',timer = <process_time()>,repeat=3,number=10000)
SyntaxError: invalid syntax
>>> timeit.repeat('a = "-".join(str(n) for n in range(100))',timer =<process_time()>,repeat=3,number=10000)
SyntaxError: invalid syntax
>>> timeit.repeat('a = "-".join(str(n) for n in range(100))',timer = process_time(),repeat=3,number=10000)
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
    timeit.repeat('a = "-".join(str(n) for n in range(100))',timer = process_time(),repeat=3,number=10000)
NameError: name 'process_time' is not defined
>>> timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()
1.1840565520001292
>>> timeit.Timer('for i in range(10): oct(i)', 'gc.enable()')
<timeit.Timer object at 0x000002311996BFD0>
>>> a=timeit.Timer('for i in range(10): oct(i)', 'gc.enable()')
>>> a
<timeit.Timer object at 0x00000231199A5EF0>
>>> a.timeit()
1.2091490960001465
>>> a.repeat()

>>> s = '''\
try:
        str.__bool__
except AttributeError:
        pass
'''
>>> timeit.timeit(stmt=s, number = 100000)
0.041749605999939376
>>> s = 'if hasattr(str,"__bool__"):pass'
>>> timeit.timeit(stmt=s, number = 100000)
0.027976809999927355
>>> s = '''\
try:
        int.__bool__
except AttributeError:
        pass
'''
>>> timeit.timeit(stmt=s, number = 100000)
0.004601171999865983
>>> s = 'if hasattr(int,"__bool__"):pass'
>>> timeit.timeit(stmt=s, number = 100000)
0.006767500000023574

timeit,repeat方法中的timer的使用,暂时还未掌握

wulljy 发表于 2018-10-1 09:37:08

如何读取文本中包含的时间

TCY 发表于 2018-10-1 21:46:26

支持小甲鱼

Kiwi- 发表于 2018-10-2 17:34:23

kk

三无学习机 发表于 2018-10-2 21:46:02

支持小甲鱼

gratelxc 发表于 2018-10-3 09:42:49

支持小甲鱼

Roden 发表于 2018-10-3 13:57:14

看看源代码

DxCaesar 发表于 2018-10-4 16:28:32

666

ssy114114 发表于 2018-10-5 07:55:43

支持楼主!

HoveMoS 发表于 2018-10-5 14:19:25

1

dguest 发表于 2018-10-6 12:10:38

小甲鱼你写错别字了,是大有裨益哈哈哈。。.

JesseMan 发表于 2018-10-8 10:23:06

{:5_90:}强路费灰飞烟灭

yuhuaab 发表于 2018-10-8 14:56:57

支持楼主
页: 42 43 44 45 46 47 48 49 50 51 [52] 53 54 55 56 57 58 59 60 61
查看完整版本: timeit 模块详解(准确测量小段代码的执行时间)