diff --git a/benchmarks/transaction_load_dump.py b/benchmarks/transaction_load_dump.py index a27836d..0837fc9 100644 --- a/benchmarks/transaction_load_dump.py +++ b/benchmarks/transaction_load_dump.py @@ -2,9 +2,10 @@ import dataclasses import datetime import decimal +import marshmallow_recipe as mr import uuid -import marshmallow_recipe as mr +from typing import Annotated @dataclasses.dataclass(frozen=True) @@ -12,8 +13,8 @@ class Transaction: id: uuid.UUID created_at: datetime.datetime processed_at: datetime.datetime | None - amount: decimal.Decimal - transaction_amount: decimal.Decimal + amount: decimal.Decimal = dataclasses.field(metadata=mr.decimal_metadata(places=4)) + transaction_amount: Annotated[decimal.Decimal, mr.decimal_metadata(places=4)] transaction = Transaction( @@ -23,10 +24,8 @@ class Transaction: amount=decimal.Decimal(42), transaction_amount=decimal.Decimal(42), ) -transactions = [transaction] * 1024 +# to warm up the lib caches +assert mr.load_many(Transaction, mr.dump_many([transaction] * 1024)) -assert mr.load_many(Transaction, mr.dump_many(transactions)) -assert mr.load_slim_many(Transaction, mr.dump_slim_many(transactions)) -cProfile.run("mr.load_slim_many(Transaction, mr.dump_slim_many(transactions))", sort='tottime') -cProfile.run("mr.load_many(Transaction, mr.dump_many(transactions))", sort='tottime') +cProfile.run("mr.load_many(Transaction, mr.dump_many([transaction] * 1024))", sort='tottime')