Skip to content

Commit b840153

Browse files
committed
Optimize test_parallel
1 parent d97aae4 commit b840153

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/test_parallel.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import concurrent.futures
33
import time
44
import sys
5-
import os
6-
import chdb
75
import unittest
6+
import chdb
87
from utils import data_file
98

109
# run query parallel in n thread and benchmark
@@ -20,30 +19,30 @@
2019
thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=thread_count)
2120

2221

23-
def run_query(query, format):
24-
res = chdb.query(query, format)
22+
def run_query(query, fmt):
23+
res = chdb.query(query, fmt)
2524
if len(res) < 2000:
2625
print(f"Error: result size is not correct {res.bytes()}")
2726
exit(1)
2827

2928

30-
def run_queries(query, format, count=query_count):
31-
for i in range(count):
32-
run_query(query, format)
29+
def run_queries(query, fmt, count=query_count):
30+
for _ in range(count):
31+
run_query(query, fmt)
3332

3433

35-
def run_queries_parallel(query, format, parallel=thread_count, count=query_count):
36-
for i in range(parallel):
37-
thread_pool.submit(run_queries, query, format, count // parallel)
34+
def run_queries_parallel(query, fmt, parallel=thread_count, count=query_count):
35+
for _ in range(parallel):
36+
thread_pool.submit(run_queries, query, fmt, count // parallel)
3837

3938

4039
def wait():
4140
thread_pool.shutdown(wait=True)
4241

4342

44-
def benchmark(query, format, parallel=thread_count, count=query_count):
43+
def benchmark(query, fmt, parallel=thread_count, count=query_count):
4544
time_start = time.time()
46-
run_queries_parallel(query, format, parallel, count)
45+
run_queries_parallel(query, fmt, parallel, count)
4746
wait()
4847
time_end = time.time()
4948
print("Time cost:", time_end - time_start, "s")

0 commit comments

Comments
 (0)