Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
arhamchopra committed Dec 7, 2023
1 parent 97b85b6 commit 59bd98e
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions run_sql_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import duckdb
import json

duckdb_file = "db.duckdb"
duckdb_query = "queries/q1.sql"
import os

con = duckdb.connect(duckdb_file)
with open(duckdb_query, "r") as sql_file:

duckdb_file = "db_small.duckdb"
duckdb_query_path = "queries"

RUN_COUNT = 13
WARMUP_COUNT = 2

for query_file in os.listdir(duckdb_query_path):
print("Running {}", query_file)

con = duckdb.connect(duckdb_file)
duckdb_query = os.path.join(duckdb_query_path, query_file)
with open(duckdb_query, "r") as sql_file:
sql_query = sql_file.read()

con.sql("PRAGMA enable_profiling='json'")
# print(sql_query)
res = con.sql(sql_query).to_df()
print(res['explain_value'][0])
res = (res['explain_value'][0])
con.sql("PRAGMA enable_profiling='json'")
# Run the query a few times to warm up memory

print("Warmup: {}", sql_query)
for _ in range(WARMUP_COUNT):
con.sql(sql_query)

times = []

print("Running test: {}", sql_query)
for i in range(RUN_COUNT):
output = con.sql(sql_query).to_df()
res_str = output['explain_value'][0]
res_dict = json.loads(res_str)
times += [float(res_dict["timing"])]

res = json.loads(res)
total_time = res["timing"]
# seq_time = res["children"]
print(f"Total Time: {total_time}")
times = sorted(times)
print("Query file: {}, min_time: {}, max_time: {}, avg_time: {}, median_time: {}", query_file, times[0], times[-1], sum(times)/RUN_COUNT, times[RUN_COUNT/2])
con.close()

con.close()
# print(res['explain_value'][0])

0 comments on commit 59bd98e

Please sign in to comment.