MCPcopy Create free account
hub / github.com/ipython/ipython / TimeitTemplateFiller

Class TimeitTemplateFiller

IPython/core/magics/execution.py:123–145  ·  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

121
122
123class TimeitTemplateFiller(ast.NodeTransformer):
124 """Fill in the AST template for timing execution.
125
126 This is quite closely tied to the template definition, which is in
127 :meth:`ExecutionMagics.timeit`.
128 """
129 def __init__(self, ast_setup, ast_stmt):
130 self.ast_setup = ast_setup
131 self.ast_stmt = ast_stmt
132
133 def visit_FunctionDef(self, node):
134 "Fill in the setup statement"
135 self.generic_visit(node)
136 if node.name == "inner":
137 node.body[:1] = self.ast_setup.body
138
139 return node
140
141 def visit_For(self, node):
142 "Fill in the statement to be timed"
143 if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
144 node.body = self.ast_stmt.body
145 return node
146
147
148class Timer(timeit.Timer):

Callers 1

timeitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected