A high-performance clock and sleep library for Python, written in Rust with
PyO3 bindings. Drop-in replacement for
PsychoPy core clocks with ~20x speedup on
clock.getTime() (~70 ns vs ~1.5 μs).
Also provides a high-accuracy sleep function that substantially outperforms
Python's time.sleep.
pip install psyquartzMonotonicClock records the current time at creation. Calling getTime()
returns the elapsed seconds since then.
import psyquartz
clock = psyquartz.MonotonicClock()
elapsed = clock.getTime() # seconds since creation
raw = clock.getTime(applyZero=False) # raw UNIX epoch timeClock extends MonotonicClock with the ability to reset and shift the
baseline.
clock = psyquartz.Clock()
print(clock.getTime()) # seconds since creation
clock.reset() # restart from 0
print(clock.getTime()) # close to 0
clock.addTime(1.0) # shift baseline forward by 1 s
print(clock.getTime()) # close to -1.0sleep (and its alias sleepers) uses a hybrid strategy — sleeping for half
the remaining duration while more than 200 μs remain, then spin-waiting for the
final stretch.
import psyquartz
psyquartz.sleep(0.01) # accurate 10 ms sleep