| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="node465.html" /> |
| 13 | <link rel="prev" href="module-timeit.html" /> |
| 14 | <link rel="parent" href="module-timeit.html" /> |
| 15 | <link rel="next" href="node465.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>10.10.1 Command Line Interface</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="10.10 timeit " |
| 25 | href="module-timeit.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="10.10 timeit " |
| 28 | href="module-timeit.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="10.10.2 Examples" |
| 31 | href="node465.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-timeit.html">10.10 timeit </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-timeit.html">10.10 timeit </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="node465.html">10.10.2 Examples</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION00121010000000000000000"> |
| 56 | 10.10.1 Command Line Interface</A> |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | When called as a program from the command line, the following form is used: |
| 61 | |
| 62 | <P> |
| 63 | <div class="verbatim"><pre> |
| 64 | python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...] |
| 65 | </pre></div> |
| 66 | |
| 67 | <P> |
| 68 | where the following options are understood: |
| 69 | |
| 70 | <P> |
| 71 | <DL> |
| 72 | <DT><STRONG>-n N/<b class="programopt">--number=N</b></STRONG></DT> |
| 73 | <DD>how many times to execute 'statement' |
| 74 | </DD> |
| 75 | <DT><STRONG>-r N/<b class="programopt">--repeat=N</b></STRONG></DT> |
| 76 | <DD>how many times to repeat the timer (default 3) |
| 77 | </DD> |
| 78 | <DT><STRONG>-s S/<b class="programopt">--setup=S</b></STRONG></DT> |
| 79 | <DD>statement to be executed once initially (default |
| 80 | <code>'pass'</code>) |
| 81 | </DD> |
| 82 | <DT><STRONG>-t/<b class="programopt">--time</b></STRONG></DT> |
| 83 | <DD>use <tt class="function">time.time()</tt> |
| 84 | (default on all platforms but Windows) |
| 85 | </DD> |
| 86 | <DT><STRONG>-c/<b class="programopt">--clock</b></STRONG></DT> |
| 87 | <DD>use <tt class="function">time.clock()</tt> (default on Windows) |
| 88 | </DD> |
| 89 | <DT><STRONG>-v/<b class="programopt">--verbose</b></STRONG></DT> |
| 90 | <DD>print raw timing results; repeat for more digits |
| 91 | precision |
| 92 | </DD> |
| 93 | <DT><STRONG>-h/<b class="programopt">--help</b></STRONG></DT> |
| 94 | <DD>print a short usage message and exit |
| 95 | </DD> |
| 96 | </DL> |
| 97 | |
| 98 | <P> |
| 99 | A multi-line statement may be given by specifying each line as a |
| 100 | separate statement argument; indented lines are possible by enclosing |
| 101 | an argument in quotes and using leading spaces. Multiple |
| 102 | <b class="programopt">-s</b> options are treated similarly. |
| 103 | |
| 104 | <P> |
| 105 | If <b class="programopt">-n</b> is not given, a suitable number of loops is |
| 106 | calculated by trying successive powers of 10 until the total time is |
| 107 | at least 0.2 seconds. |
| 108 | |
| 109 | <P> |
| 110 | The default timer function is platform dependent. On Windows, |
| 111 | <tt class="function">time.clock()</tt> has microsecond granularity but |
| 112 | <tt class="function">time.time()</tt>'s granularity is 1/60th of a second; on <span class="Unix">Unix</span>, |
| 113 | <tt class="function">time.clock()</tt> has 1/100th of a second granularity and |
| 114 | <tt class="function">time.time()</tt> is much more precise. On either platform, the |
| 115 | default timer functions measure wall clock time, not the CPU time. |
| 116 | This means that other processes running on the same computer may |
| 117 | interfere with the timing. The best thing to do when accurate timing |
| 118 | is necessary is to repeat the timing a few times and use the best |
| 119 | time. The <b class="programopt">-r</b> option is good for this; the default of 3 |
| 120 | repetitions is probably enough in most cases. On <span class="Unix">Unix</span>, you can use |
| 121 | <tt class="function">time.clock()</tt> to measure CPU time. |
| 122 | |
| 123 | <P> |
| 124 | <div class="note"><b class="label">Note:</b> |
| 125 | There is a certain baseline overhead associated with executing a |
| 126 | pass statement. The code here doesn't try to hide it, but you |
| 127 | should be aware of it. The baseline overhead can be measured by |
| 128 | invoking the program without arguments. |
| 129 | </div> |
| 130 | |
| 131 | <P> |
| 132 | The baseline overhead differs between Python versions! Also, to |
| 133 | fairly compare older Python versions to Python 2.3, you may want to |
| 134 | use Python's <b class="programopt">-O</b> option for the older versions to avoid |
| 135 | timing <code>SET_LINENO</code> instructions. |
| 136 | |
| 137 | <P> |
| 138 | |
| 139 | <DIV CLASS="navigation"> |
| 140 | <div class='online-navigation'> |
| 141 | <p></p><hr /> |
| 142 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 143 | <tr> |
| 144 | <td class='online-navigation'><a rel="prev" title="10.10 timeit " |
| 145 | href="module-timeit.html"><img src='../icons/previous.png' |
| 146 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 147 | <td class='online-navigation'><a rel="parent" title="10.10 timeit " |
| 148 | href="module-timeit.html"><img src='../icons/up.png' |
| 149 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 150 | <td class='online-navigation'><a rel="next" title="10.10.2 Examples" |
| 151 | href="node465.html"><img src='../icons/next.png' |
| 152 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 153 | <td align="center" width="100%">Python Library Reference</td> |
| 154 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 155 | href="contents.html"><img src='../icons/contents.png' |
| 156 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 157 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 158 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 159 | <td class='online-navigation'><a rel="index" title="Index" |
| 160 | href="genindex.html"><img src='../icons/index.png' |
| 161 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 162 | </tr></table> |
| 163 | <div class='online-navigation'> |
| 164 | <b class="navlabel">Previous:</b> |
| 165 | <a class="sectref" rel="prev" href="module-timeit.html">10.10 timeit </A> |
| 166 | <b class="navlabel">Up:</b> |
| 167 | <a class="sectref" rel="parent" href="module-timeit.html">10.10 timeit </A> |
| 168 | <b class="navlabel">Next:</b> |
| 169 | <a class="sectref" rel="next" href="node465.html">10.10.2 Examples</A> |
| 170 | </div> |
| 171 | </div> |
| 172 | <hr /> |
| 173 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 174 | </DIV> |
| 175 | <!--End of Navigation Panel--> |
| 176 | <ADDRESS> |
| 177 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 178 | </ADDRESS> |
| 179 | </BODY> |
| 180 | </HTML> |