From d4a9d5b0b3a3d26fb283c6a1318061bf97c90bbd Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 29 Apr 2025 22:20:48 -0400 Subject: add reactiontime script --- reactiontime | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 reactiontime diff --git a/reactiontime b/reactiontime new file mode 100755 index 0000000..292845e --- /dev/null +++ b/reactiontime @@ -0,0 +1,40 @@ +#!/usr/bin/env python +import random +import datetime +import time +import sys +import pathlib + + +def as_millis(s): + return s*1000 + + +def take_sample(): + waittime = random.randint(0,5) + time.sleep(waittime) + start=datetime.datetime.now() + sys.stderr.write("GO") + sys.stderr.flush() + input() + end=datetime.datetime.now() + delta = end - start + return as_millis(delta.total_seconds()) + + +def record_metric(avg, log: pathlib.Path): + now = datetime.datetime.now() + with log.open('a+', encoding='utf-8') as f: + f.write(f"{now}\t{avg}\n") + f.flush() + + +if __name__ == "__main__": + samples = [] + n = 5 + print("Press Enter when you see GO") + for i in range(0, n): + samples.append(take_sample()) + avg = sum(samples)/n + record_metric(avg, pathlib.Path("~/org/reactiontime.log").expanduser()) + print(avg) -- cgit v1.2.3