Apologies for reposting but I had to edit this question when I got to work and realized I needed to have an account to do so. So here it goes again (with a little more context).
I'm trying to time how long a script takes to execute, and I am thinking of doing that by checking the elapsed time after every line of code is executed. I've done this before when the script has contained method definitions, but am not sure how it would work in this instance.
So my question is: Is there a way to use the setTrace() function in a script that has no method definitions? i.e.
for i in range(1, 100):
print i
def traceit(frame, event, arg):
if event == "line":
lineno = frame.f_lineno
print "line", lineno
return traceit
sys.settrace(traceit)