In [3]:
from psychopy import visual, core, event
import numpy as np
In [3]:
win = visual.Window()
core.wait(1)
win.close()
In [7]:
# Create a window and a circle
win = visual.Window()
circle = visual.Circle(win, radius=0.1)
# Show the circle until keypress
circle.draw()
win.flip()
event.waitKeys()
# Close the window
win.close()
In [6]:
# Parameters in the experiment
nTrials = 5
reaction_times = []
# Create a window and the circle
win = visual.Window()
circle = visual.Circle(win, radius=0.1)
# Run the trials
for t in np.arange(nTrials):
# Show an empty screen for 1 second
win.flip()
core.wait(1)
# Show the circle until keypress
circle.draw()
win.flip()
keypressed = False
t0 = core.getTime()
while not keypressed:
k = event.getKeys()
if k:
reaction_times.append(core.getTime() - t0)
break
# Close the window
win.close()
print(np.array(reaction_times) * 1000) # in ms
In [17]:
import time
import matplotlib.pyplot as plt
# Run nLoops iterations
nLoops = 10000
loop_times = []
for i in range(nLoops):
loop_times.append(time.time())
# The difference between two values are the loop-times (in microseconds)
loop_dur = np.diff(loop_times) * 1000000
# Plot the results as a histogram (in milliseconds). Set the axis to [-1, +1] ms
plt.hist(loop_dur, bins=100, range = (-1, 1))
plt.show()
# Compute the M \pm SD of loop-time
print('%.2f %.2f' % (np.mean(loop_dur), np.std(loop_dur)))
Conclusion: The loop times are tiny; on average they are less than 1 microsecond.
In [ ]: