wj465596344 发表于 2018-4-26 20:55:19

学习学习

cai0000niao 发表于 2018-4-27 10:44:15

{:10_265:}

cm1986 发表于 2018-4-27 18:04:04

好好学习

yuyuyuyuyuyu 发表于 2018-4-29 23:09:37

mark

菩萨的左手 发表于 2018-5-2 10:28:56

学习学习

fish_admin 发表于 2018-5-2 13:38:41

休息一下继续学习

whatever614 发表于 2018-5-3 10:37:06

谢谢

cestlavieoccupe 发表于 2018-5-4 03:20:01

还有隐藏内容??

编程教父孙笑川 发表于 2018-5-4 15:11:56

good

373074501 发表于 2018-5-5 16:34:52

感谢小甲鱼!!!

WFWT 发表于 2018-5-6 12:57:54

只是想看代码

gongmcgrady 发表于 2018-5-7 17:57:17

正文没看太懂,看看代码

fuwaandhuluwa 发表于 2018-5-8 10:35:40

小甲鱼老师,我有个问题:使用timeit模块测量小段代码的执行时间,特别是对多行代码的时候,使用“”“多行代码”“”这种方式赋值stmt,相比于使用setup和globals设置命名空间的测量时间都小。这是为什么,同样的代码测量的执行时间却大不一样!代码如下所示
>>> s = """
class A:
        def func1(self):
                for x in range(100):
                        self.count += x
                return self.count
        def __init__(self):
                self.count = 0

a = A()
a.func1()
"""
>>> timeit.timeit(stmt=s, number=100000)
2.182303924016196
>>> a
<__main__.A object at 0x03207D70>
>>> timeit.timeit(stmt = "func1()", setup = 'from __main__ import func1 ')
4.584396307330735
>>> timeit.timeit(stmt = "func1()", setup = 'from __main__ import func1 ')
4.5826148827454745
>>> repeat(stmt = "func1()", setup = 'from __main__ import func1 ')
Traceback (most recent call last):
File "<pyshell#83>", line 1, in <module>
    repeat(stmt = "func1()", setup = 'from __main__ import func1 ')
NameError: name 'repeat' is not defined
>>> timeit.repeat(stmt = "func1()", setup = 'from __main__ import func1 ')

>>> timeit('a.func1()',globals = globals())
Traceback (most recent call last):
File "<pyshell#85>", line 1, in <module>
    timeit('a.func1()',globals = globals())
TypeError: 'module' object is not callable
>>> a
<__main__.A object at 0x03207D70>
>>> a.func1()
14850
>>> timeit.timeit('a.func1()',globals = globals())
14.001687110608145

jun@ 发表于 2018-5-8 15:34:01

hi

leonwaters 发表于 2018-5-8 19:12:58

学习一下

farseerrenhui 发表于 2018-5-10 14:46:11

回复一下看看源代码

navy_z 发表于 2018-5-10 22:53:35

good

时临1 发表于 2018-5-11 10:31:59

{:5_91:}

Replus 发表于 2018-5-11 20:16:54

get

wangyinghan 发表于 2018-5-13 21:42:29

1
页: 31 32 33 34 35 36 37 38 39 40 [41] 42 43 44 45 46 47 48 49 50
查看完整版本: timeit 模块详解(准确测量小段代码的执行时间)