MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __init__

Method __init__

tools/python-3.11.9-amd64/Lib/timeit.py:104–137  ·  view source on GitHub ↗

Constructor. See class doc string.

(self, stmt="pass", setup="pass", timer=default_timer,
                 globals=None)

Source from the content-addressed store, hash-verified

102 """
103
104 def __init__(self, stmt="pass", setup="pass", timer=default_timer,
105 globals=None):
106 """Constructor. See class doc string."""
107 self.timer = timer
108 local_ns = {}
109 global_ns = _globals() if globals is None else globals
110 init = ''
111 if isinstance(setup, str):
112 # Check that the code can be compiled outside a function
113 compile(setup, dummy_src_name, "exec")
114 stmtprefix = setup + '\n'
115 setup = reindent(setup, 4)
116 elif callable(setup):
117 local_ns['_setup'] = setup
118 init += ', _setup=_setup'
119 stmtprefix = ''
120 setup = '_setup()'
121 else:
122 raise ValueError("setup is neither a string nor callable")
123 if isinstance(stmt, str):
124 # Check that the code can be compiled outside a function
125 compile(stmtprefix + stmt, dummy_src_name, "exec")
126 stmt = reindent(stmt, 8)
127 elif callable(stmt):
128 local_ns['_stmt'] = stmt
129 init += ', _stmt=_stmt'
130 stmt = '_stmt()'
131 else:
132 raise ValueError("stmt is neither a string nor callable")
133 src = template.format(stmt=stmt, setup=setup, init=init)
134 self.src = src # Save for traceback display
135 code = compile(src, dummy_src_name, "exec")
136 exec(code, global_ns, local_ns)
137 self.inner = local_ns["inner"]
138
139 def print_exc(self, file=None):
140 """Helper to print a traceback from the timed code.

Callers

nothing calls this directly

Calls 4

reindentFunction · 0.85
compileFunction · 0.70
callableFunction · 0.50
formatMethod · 0.45

Tested by

no test coverage detected