Time execution of a Python statement or expression **Usage, in line mode**:: %timeit [-n -r [-t|-c] -q -p [-o|-v ]] statement **or in cell mode**:: %%timeit [-n -r [-t|-c] -q -p [-o|-v ]] setup_code code code...
(self, line='', cell=None, local_ns=None)
| 1063 | @line_cell_magic |
| 1064 | @needs_local_scope |
| 1065 | def timeit(self, line='', cell=None, local_ns=None): |
| 1066 | """Time execution of a Python statement or expression |
| 1067 | |
| 1068 | **Usage, in line mode**:: |
| 1069 | |
| 1070 | %timeit [-n<N> -r<R> [-t|-c] -q -p<P> [-o|-v <V>]] statement |
| 1071 | |
| 1072 | **or in cell mode**:: |
| 1073 | |
| 1074 | %%timeit [-n<N> -r<R> [-t|-c] -q -p<P> [-o|-v <V>]] setup_code |
| 1075 | code |
| 1076 | code... |
| 1077 | |
| 1078 | Time execution of a Python statement or expression using the timeit |
| 1079 | module. This function can be used both as a line and cell magic: |
| 1080 | |
| 1081 | - In line mode you can time a single-line statement (though multiple |
| 1082 | ones can be chained with using semicolons). |
| 1083 | |
| 1084 | - In cell mode, the statement in the first line is used as setup code |
| 1085 | (executed but not timed) and the body of the cell is timed. The cell |
| 1086 | body has access to any variables created in the setup code. |
| 1087 | |
| 1088 | Options: |
| 1089 | |
| 1090 | -n<N> |
| 1091 | Execute the given statement N times in a loop. If N is not |
| 1092 | provided, N is determined so as to get sufficient accuracy. |
| 1093 | |
| 1094 | -r<R> |
| 1095 | Number of repeats R, each consisting of N loops, and take the |
| 1096 | average result. |
| 1097 | Default: 7 |
| 1098 | |
| 1099 | -t |
| 1100 | Use ``time.time`` to measure the time, which is the default on Unix. |
| 1101 | This function measures wall time. |
| 1102 | |
| 1103 | -c |
| 1104 | Use ``time.clock`` to measure the time, which is the default on |
| 1105 | Windows and measures wall time. On Unix, ``resource.getrusage`` is used |
| 1106 | instead and returns the CPU user time. |
| 1107 | |
| 1108 | -p<P> |
| 1109 | Use a precision of P digits to display the timing result. |
| 1110 | Default: 3 |
| 1111 | |
| 1112 | -q |
| 1113 | Quiet, do not print result. |
| 1114 | |
| 1115 | -o |
| 1116 | Return a ``TimeitResult`` that can be stored in a variable to inspect |
| 1117 | the result in more details. |
| 1118 | |
| 1119 | -v <V> |
| 1120 | Like ``-o``, but save the ``TimeitResult`` directly to variable <V>. |
| 1121 | |
| 1122 | .. versionchanged:: 7.3 |
nothing calls this directly
no test coverage detected