This is the outline of a simple program
# some pre-defined constants
A = 1
B = 2
# function that does something critical
def foo(num1, num2):
# do somet
The code snippets must be self-contained - they cannot make external references. You must define your values in the statement-string or setup-string:
import timeit
setup = """
A = 1
B = 2
def foo(num1, num2):
pass
def mainprog():
global A,B
for i in range(20):
# do something to A and B
foo(A, B)
"""
t = timeit.Timer(stmt="mainprog()" setup=setup)
print(t.timeit(5))
Better yet, rewrite your code to not use global values.