|
2 | 2 | import concurrent.futures |
3 | 3 | import time |
4 | 4 | import sys |
5 | | -import os |
6 | | -import chdb |
7 | 5 | import unittest |
| 6 | +import chdb |
8 | 7 | from utils import data_file |
9 | 8 |
|
10 | 9 | # run query parallel in n thread and benchmark |
|
20 | 19 | thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) |
21 | 20 |
|
22 | 21 |
|
23 | | -def run_query(query, format): |
24 | | - res = chdb.query(query, format) |
| 22 | +def run_query(query, fmt): |
| 23 | + res = chdb.query(query, fmt) |
25 | 24 | if len(res) < 2000: |
26 | 25 | print(f"Error: result size is not correct {res.bytes()}") |
27 | 26 | exit(1) |
28 | 27 |
|
29 | 28 |
|
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) |
33 | 32 |
|
34 | 33 |
|
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) |
38 | 37 |
|
39 | 38 |
|
40 | 39 | def wait(): |
41 | 40 | thread_pool.shutdown(wait=True) |
42 | 41 |
|
43 | 42 |
|
44 | | -def benchmark(query, format, parallel=thread_count, count=query_count): |
| 43 | +def benchmark(query, fmt, parallel=thread_count, count=query_count): |
45 | 44 | time_start = time.time() |
46 | | - run_queries_parallel(query, format, parallel, count) |
| 45 | + run_queries_parallel(query, fmt, parallel, count) |
47 | 46 | wait() |
48 | 47 | time_end = time.time() |
49 | 48 | print("Time cost:", time_end - time_start, "s") |
|
0 commit comments