Форум сайта python.su
t = timeit.Timer(“test1(sent,rd)”)
>>> t.timeit()
Traceback (most recent call last):
File “<pyshell#154>”, line 1, in <module>
t.timeit()
File “C:\Python25\lib\timeit.py”, line 161, in timeit
timing = self.inner(it, self.timer)
File “<timeit-src>”, line 6, in inner
NameError: global name ‘test1’ is not defined
>>> globals()
{'a': ‘qwer23’, ‘test1’: <function test1 at 0x019AEBF0>, ‘timeit’: <module ‘timeit’ from ‘C:\Python25\lib\timeit.pyc’>,
Офлайн
t = timeit.Timer("test1(sent,rd)", 'from __main__ import test1')
Офлайн
>>> sent='hghn'
>>> rd='fdg'
>>> def test1(sent,rd):
a=sent+rd
>>> if __name__=='__main__':
from timeit import Timer
t = Timer(“test1(sent,rd)”, “from __main__ import test1”)
print t.timeit()
Traceback (most recent call last):
File “<pyshell#6>”, line 4, in <module>
print t.timeit()
File “C:\Python25\lib\timeit.py”, line 161, in timeit
timing = self.inner(it, self.timer)
File “<timeit-src>”, line 6, in inner
NameError: global name ‘sent’ is not defined
>>>
Офлайн
t = Timer(“test1(sent,rd)”, ‘from __main__ import test1,sent,rd’)
Офлайн
питання вирішено
Офлайн
Понимаю, что топик стар как мир, однако хотел спросить.
почему результирующее время такое огромное становится?
вот пример:
>>> list1 = [7, 2, 3, 10, 12]
>>> list2 = [-1, 1, -5, 4, 6]
>>> from timeit import timeit as ti
>>> ti('map(lambda x, y: x*y, list1, list2)', 'from __main__ import list1, list2')
8.450500659762035
>>> ti('map(lambda x, y: x*y, list1, list2)', 'from __main__ import list1, list2')
8.715931700531947
Офлайн
list1 = [7, 2, 3, 10, 12]
list2 = [-1, 1, -5, 4, 6]
from timeit import timeit as ti
ti('map(lambda x, y: x*y, list1, list2)', 'from __main__ import list1, list2', number=1)
7.69909474129804e-06
Офлайн