blob: 292845e5669e1c5bf597b3ad91e38509e5f8e4e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
|