47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import pytest
|
|
from sqlalchemy.orm import Session
|
|
|
|
from dibbler.models import Product, User
|
|
from dibbler.queries import transaction_log
|
|
from tests.benchmark.helpers import generate_random_transactions, insert_users_and_products
|
|
|
|
|
|
@pytest.mark.benchmark(group='transaction_log')
|
|
@pytest.mark.parametrize(
|
|
"transaction_count",
|
|
[
|
|
100,
|
|
500,
|
|
1000,
|
|
2000,
|
|
5000,
|
|
10000,
|
|
],
|
|
)
|
|
def test_benchmark_transaction_log(benchmark, sql_session: Session, transaction_count: int):
|
|
users, products = insert_users_and_products(sql_session)
|
|
|
|
generate_random_transactions(
|
|
sql_session,
|
|
transaction_count,
|
|
)
|
|
|
|
benchmark.pedantic(
|
|
query_transaction_log,
|
|
args=(
|
|
sql_session,
|
|
products,
|
|
users,
|
|
),
|
|
iterations=10,
|
|
rounds=5,
|
|
)
|
|
|
|
|
|
def query_transaction_log(sql_session: Session, products: list[Product], users: list[User]) -> None:
|
|
for user in users:
|
|
transaction_log(sql_session, user=user)
|
|
|
|
for product in products:
|
|
transaction_log(sql_session, product=product)
|