Namespace for timeit
ROGER GRAYDON CHRISTMAN
dvl at psu.edu
Fri Oct 14 08:54:28 EDT 2016
Trying to use timeit within a function:
def test(name, sorter, size):
"""Tests and times the sorting algorithm on given array size"""
print(name,end='\t')
array = [0]*size
for i in range(size):
array[i] = randrange(2000000000)
timeit('sorter( array, size )', number=1)
Since 'sorter' is a name local to test, it is not yet recognized by timeit,
so I know I must somehow define a new namespace for that,
but the documentation doesn't really help me with how to do that
timeit('sorter( array, size )', number=1, globals='test')
That tells me the namespace isn't supposed to be a string
test.__dict__ is just an empty dictionary
so where do I find 'sorter', 'array', and 'size'?
Roger Christman
Pennsylvania State University
More information about the Python-list
mailing list