-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.py
48 lines (37 loc) · 1.24 KB
/
benchmark.py
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
import clickhouse_driver
from datetime import datetime
import duckdb
# Number of times to benchmark each query
ITERATIONS = 10
# Names of queries to load from the "./queries/" folder
BENCHMARKS = ["groupby", "self-join"]
def benchmark_db(db, execute_fn):
""" Benchmarks all queries against one datastore """
for name in BENCHMARKS:
# Load query
with open(f"queries/{name}.{db}.sql") as f:
query = f.read()
# Run benchmark and track query durations
deltas = []
for _ in range(ITERATIONS):
start = datetime.now()
execute_fn(query)
end = datetime.now()
deltas.append((end - start).total_seconds())
# Print result
avg = sum(deltas) / len(deltas)
print("{}:{}: avg={:.3f}s min={:.3f}s max={:.3f}s ({} runs)".format(
db,
name,
avg,
min(deltas),
max(deltas),
ITERATIONS,
))
def main():
ddb = duckdb.connect("./duckdb/db.duckdb")
benchmark_db("duckdb", lambda query: ddb.execute(query))
ch = clickhouse_driver.Client(host='localhost')
benchmark_db("clickhouse", lambda query: ch.execute(query))
if __name__ == "__main__":
main()