forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97b85b6
commit 59bd98e
Showing
1 changed file
with
33 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |