Cognitive psychological experiments typically require the precise measurement of time. Typically, we deal with time in milliseconds. In one second are exactly 1000 milliseconds (abbreviated "ms").
It takes a person at least 150 ms to respond to a simple stimulus. It takes a person at least 250 ms to respond to a stimulus which requires a decision (e.g., discriminating its color or shape). |
Apart from readkey most of the functions described here are advanced functions that few users will need. |
Measuring time it takes to press button
In PsyToolkit, it is super simple to measure the time it takes to respond with a keyboard buttonpress to a stimulus.
In the very simple example below, all we do is show a yellow rectangle. You need to respond to it with the button b. The function readkey has two arguments. The first says that you must respond with the first key listed in the keys (b). You need to respond with 3000 milliseconds.
After the readkey command, the first presented stimulus is deleted from the screen. Then the save line stores both the reaction time RT and the correctness STATUS in the output data file. The STATUS can have 3 values (1=correct, 2=wrong key, 3=too slow).
The save line
task my_task
keys b
show rectangle 0 0 20 20 255 255 0
readkey 1 3000
clear 1
save RT STATUS
Getting time since start of an experiment
Sometimes you just want to know the time since the start of the experiment. Actually, this is only a somewhat advanced function that few people will need.
task my_task
keys b
show rectangle 0 0 20 20 255 255 0
readkey 1 3000
clear 1
set $my_time time-since-start
save $my_time RT STATUS
Time stamps
Sometimes you want to know the difference between two times in an experiment. In PsyToolkit, you can at any time set a timestamp. This keeps the real time in a special time stamp variable. You can later get the difference between two timestamps.
task my_task
keys b
timestamp myFirstTimeStamp
show rectangle 0 0 20 20 255 255 0
delay 1000
show rectangle 0 0 20 20 100 100 255
delay 1000
timestamp mySecondTimeStamp
set $my_difference timestamp-diff myFirstTimeStamp mySecondTimeStamp
save $my_difference
Getting the precise absolute current time in seconds
You can get the absolute time of a PsyToolkit timestamp in seconds since the first of January 1970. You can also get the milliseconds.
This is nice for getting absolute time, but see also the simpler unix-time below. |
task my_task
keys b
timestamp myTimeStamp
show rectangle 0 0 20 20 255 255 0
readkey 1 3000
clear 1
set $time_in_sec timestamp-seconds myTimeStamp
set $rest_time_in_ms timestamp-milliseconds myTimeStamp
set $absolute_time expression $time_in_sec * 1000 + $rest_time_in_ms
save $time_in_sec $rest_time_in_ms $absolute_time
Getting the precise absolute current time
Some researchers want the absolute current time. A common practise for this is the time in milliseconds since the 1st of January 1970 (know as Unix Time).
This can be useful if you want to compare your time with another computer. This is an advanced function that few people will need.
task my_task
keys b
show rectangle 0 0 20 20 255 255 0
readkey 1 3000
clear 1
set $my_time time-since-start
save $my_time RT STATUS