Here's one solution that worked for me in this exact situation, until your arguments are huge matrices or something like that.
Let's say that I want to test the function foo (a, b, c) with the values ββthat I initialized inside my main function. I can make the following call without changing my code,
timeit.Timer('foo({},{},{})'.format(a,b,c), "from __main__ import foo")
If your arguments are strings, you must retype the quotation marks around the values:
timeit.Timer('foo("{}","{}","{}")'.format(a,b,c), "from __main__ import foo")
As a final warning, you should consider that your arguments will pass through the str () format, which may lead to their loss of precision and integrity of various types. Please check your inputs if you use this method!
source share