Skip to content

Commit 7f9cc56

Browse files
authored
Update timeit.py
- carry co_flags obtained from global setup - update timeit() and repeat() functions
1 parent a63c5f1 commit 7f9cc56

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Lib/timeit.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(self, stmt="pass", setup="pass", timer=default_timer,
129129
raise ValueError("global_setup is neither a string nor callable")
130130
if isinstance(setup, str):
131131
# Check that the code can be compiled outside a function
132-
compile(setup, dummy_src_name, "exec")
132+
compile(setup, dummy_src_name, "exec", **compile_options)
133133
stmtprefix = setup + '\n'
134134
setup = reindent(setup, 4)
135135
elif callable(setup):
@@ -141,7 +141,7 @@ def __init__(self, stmt="pass", setup="pass", timer=default_timer,
141141
raise ValueError("setup is neither a string nor callable")
142142
if isinstance(stmt, str):
143143
# Check that the code can be compiled outside a function
144-
compile(stmtprefix + stmt, dummy_src_name, "exec")
144+
compile(stmtprefix + stmt, dummy_src_name, "exec", **compile_options)
145145
stmt = reindent(stmt, 8)
146146
elif callable(stmt):
147147
local_ns['_stmt'] = stmt
@@ -252,15 +252,17 @@ def autorange(self, callback=None):
252252

253253

254254
def timeit(stmt="pass", setup="pass", timer=default_timer,
255-
number=default_number, globals=None):
255+
number=default_number, globals=None,
256+
*, global_setup="pass"):
256257
"""Convenience function to create Timer object and call timeit method."""
257-
return Timer(stmt, setup, timer, globals).timeit(number)
258+
return Timer(stmt, setup, timer, globals, global_setup=global_setup).timeit(number)
258259

259260

260261
def repeat(stmt="pass", setup="pass", timer=default_timer,
261-
repeat=default_repeat, number=default_number, globals=None):
262+
repeat=default_repeat, number=default_number, globals=None,
263+
*, global_setup="pass"):
262264
"""Convenience function to create Timer object and call repeat method."""
263-
return Timer(stmt, setup, timer, globals).repeat(repeat, number)
265+
return Timer(stmt, setup, timer, globals, global_setup=global_setup).repeat(repeat, number)
264266

265267

266268
def main(args=None, *, _wrap_timer=None):

0 commit comments

Comments
 (0)