MCPcopy Index your code
hub / github.com/ipython/ipython / TimeitTemplateFiller

Class TimeitTemplateFiller

IPython/core/magics/execution.py:137–159  ·  view source on GitHub ↗

Fill in the AST template for timing execution. This is quite closely tied to the template definition, which is in :meth:`ExecutionMagics.timeit`.

Source from the content-addressed store, hash-verified

135
136
137class TimeitTemplateFiller(ast.NodeTransformer):
138 """Fill in the AST template for timing execution.
139
140 This is quite closely tied to the template definition, which is in
141 :meth:`ExecutionMagics.timeit`.
142 """
143 def __init__(self, ast_setup, ast_stmt):
144 self.ast_setup = ast_setup
145 self.ast_stmt = ast_stmt
146
147 def visit_FunctionDef(self, node):
148 "Fill in the setup statement"
149 self.generic_visit(node)
150 if node.name == "inner":
151 node.body[:1] = self.ast_setup.body
152
153 return node
154
155 def visit_For(self, node):
156 "Fill in the statement to be timed"
157 if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
158 node.body = self.ast_stmt.body
159 return node
160
161
162class Timer(timeit.Timer):

Callers 1

timeitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…