-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlarge_average.py
More file actions
49 lines (34 loc) · 1.13 KB
/
Copy pathlarge_average.py
File metadata and controls
49 lines (34 loc) · 1.13 KB
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
41
42
43
44
45
46
47
48
49
import kronicler
from random import randint
import time
DB = kronicler.Database(sync_consume=True)
# This version of the script computes a ground truth in memory. This doesn't
# scale super well and costs a lot of memory.
# The test ./large_average_no_in_mem_comp.py does not do this, so you can
# compare the speed of this test against that one.
ground_truth_data = []
def mean(data: list):
return sum(data) / len(data)
def foo():
for _ in range(100_000):
a = randint(100, 200)
b = randint(300, 400)
DB.capture("jake", [], a, b)
ground_truth_data.append(b - a)
start = time.time()
foo()
total = time.time() - start
print(f"Running insert took {total}")
fetched = DB.fetch(0)
print("First row:", fetched)
fetched = DB.fetch_all()
print(f"Fetched all {len(fetched)} rows.")
start = time.time()
kr_avg = DB.average("jake")
kr_avg_time = time.time() - start
print("Kronicler average: ", kr_avg, f"ran in {kr_avg_time}.")
start = time.time()
py_avg = mean(ground_truth_data)
py_avg_time = time.time() - start
print("Ground truth average: ", py_avg, f"ran in {py_avg_time}.")
assert kr_avg - py_avg < 0.0001