joon
joon

Reputation: 4017

Is it possible to use Python to measure response time?

I'm running some experiments and I need to precisely measure participants' response time to questions. I know there are some commercial software, but I was wondering if I can do this with Python. Does python provides suitable functionality to measure the response time in millisecond unit?

Thank you, Joon

Upvotes: 2

Views: 5762

Answers (3)

Mentalikryst
Mentalikryst

Reputation: 760

Just do something like this:

from time import time
starttime = time()
askQuestion()
timetaken = time() - starttime

Upvotes: 4

Jungle Hunter
Jungle Hunter

Reputation: 7285

You could measure the execution time between the options displayed and the input received.

http://docs.python.org/library/timeit.html

def whatYouWantToMeasure():
    pass

if __name__=='__main__':
    from timeit import Timer
    t = Timer("whatYouWantToMeasure()", "from __main__ import test")
    print t.timeit(number=1)

Upvotes: 2

inspectorG4dget
inspectorG4dget

Reputation: 113975

You might want to look at the timeit module.

import timeit

Upvotes: 1

Related Questions