Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def chclient(request):
async with aiohttp.ClientSession() as s:
yield ChClient(s, **request.param)
async def nulls():
async with ClientSession() as s:
client = ChClient(s, compress_response=True)
assert await client.is_alive()
assert await client.is_alive()
await client.execute("DROP TABLE IF EXISTS t")
await client.execute(
"CREATE TABLE t (a Nullable(UInt8), b Tuple(Nullable(UInt8), UInt8)) ENGINE = Memory"
)
await client.execute("INSERT INTO t VALUES (NULL, (NULL, 1))")
print(await client.fetch("SELECT * FROM t"))
async def bench_inserts(*, retries: int, rows: int):
print("AIOCHCLIENT inserts")
async with ClientSession() as s:
client = ChClient(s, compress_response=True)
# prepare environment
await prepare_db(client)
# actual testing
one_row = row_data()
start_time = time.time()
for _ in range(retries):
await client.execute(
"INSERT INTO benchmark_tbl VALUES", *(one_row for _ in range(rows))
)
total_time = time.time() - start_time
avg_time = total_time / retries
speed = int(1 / avg_time * rows)
print(
f"- Avg time for inserting {rows} rows from {retries} runs: {avg_time} sec. Total: {total_time}"
)
print(f" Speed: {speed} rows/sec")
async def main():
async with ClientSession() as s:
client = ChClient(s, compress_response=True)
assert await client.is_alive()
await client.execute("DROP TABLE IF EXISTS all_types")
await client.execute("DROP TABLE IF EXISTS t")
await client.execute(
"""
CREATE TABLE all_types (a UInt8,
b UInt16,
c UInt32,
d UInt64,
e Int8,
f Int16,
g Int32,
h Int64,
i Float32,
j Float64,
k String,
async def bench_selects_with_decoding(*, retries: int, rows: int):
print("AIOCHCLIENT selects with decoding")
async with ClientSession() as s:
client = ChClient(s, compress_response=True)
# prepare environment
await prepare_db(client)
await insert_rows(client, row_data(), rows)
# actual testing
start_time = time.time()
for _ in range(retries):
selected_rows = await client.fetch("SELECT * FROM benchmark_tbl")
# decoding:
selected_rows = [row[0] for row in selected_rows]
total_time = time.time() - start_time
avg_time = total_time / retries
speed = int(1 / avg_time * rows)
print(
f"- Avg time for selecting {rows} rows from {retries} runs: {avg_time} sec (with decoding). Total: {total_time}"
)
print(f" Speed: {speed} rows/sec")
async def bench_selects(*, retries: int, rows: int):
print("AIOCHCLIENT selects")
async with ClientSession() as s:
client = ChClient(s)
# prepare environment
await prepare_db(client)
await insert_rows(client, row_data(), rows)
# actual testing
start_time = time.time()
for _ in range(retries):
await client.fetch("SELECT * FROM benchmark_tbl")
total_time = time.time() - start_time
avg_time = total_time / retries
speed = int(1 / avg_time * rows)
print(
f"- Avg time for selecting {rows} rows from {retries} runs: {avg_time} sec. Total: {total_time}"
)
print(f" Speed: {speed} rows/sec")