>>> 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)
[0.21651620500006175, 0.22220623099997283, 0.21522767299995849]
>>> 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()
[1.1775791850000132, 1.2054382349999742, 1.1808787390000361, 1.1793837000000167, 1.1820034329998634]
>>> 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