Trying to use timeit within a function:

def test(name, sorter, size):
    """Tests and times the sorting algorithm on given array size"""
    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


Reply via email to