Commit 84d9dbaa authored by Senthil Kumaran's avatar Senthil Kumaran

Fix closes Issue12697 - Update the usage syntax of timeit module in the docs.

parent e907f48c
...@@ -195,13 +195,13 @@ interface) that compare the cost of using :func:`hasattr` vs. ...@@ -195,13 +195,13 @@ interface) that compare the cost of using :func:`hasattr` vs.
:keyword:`try`/:keyword:`except` to test for missing and present object :keyword:`try`/:keyword:`except` to test for missing and present object
attributes. :: attributes. ::
% timeit.py 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass' $ python -m timeit 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
100000 loops, best of 3: 15.7 usec per loop 100000 loops, best of 3: 15.7 usec per loop
% timeit.py 'if hasattr(str, "__nonzero__"): pass' $ python -m timeit 'if hasattr(str, "__nonzero__"): pass'
100000 loops, best of 3: 4.26 usec per loop 100000 loops, best of 3: 4.26 usec per loop
% timeit.py 'try:' ' int.__nonzero__' 'except AttributeError:' ' pass' $ python -m timeit 'try:' ' int.__nonzero__' 'except AttributeError:' ' pass'
1000000 loops, best of 3: 1.43 usec per loop 1000000 loops, best of 3: 1.43 usec per loop
% timeit.py 'if hasattr(int, "__nonzero__"): pass' $ python -m timeit 'if hasattr(int, "__nonzero__"): pass'
100000 loops, best of 3: 2.23 usec per loop 100000 loops, best of 3: 2.23 usec per loop
:: ::
...@@ -242,12 +242,12 @@ To give the :mod:`timeit` module access to functions you define, you can pass a ...@@ -242,12 +242,12 @@ To give the :mod:`timeit` module access to functions you define, you can pass a
``setup`` parameter which contains an import statement:: ``setup`` parameter which contains an import statement::
def test(): def test():
"Stupid test function" """Stupid test function"""
L = [] L = []
for i in range(100): for i in range(100):
L.append(i) L.append(i)
if __name__=='__main__': if __name__ == '__main__':
from timeit import Timer from timeit import Timer
t = Timer("test()", "from __main__ import test") t = Timer("test()", "from __main__ import test")
print t.timeit() print t.timeit()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment