diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2006060 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +run: + @python main.py diff --git a/benchmark/factories.py b/benchmark/factories.py index c5e9c62..33c9d36 100644 --- a/benchmark/factories.py +++ b/benchmark/factories.py @@ -9,8 +9,8 @@ from benchmark.pydantic_benchmark.models import ( ) -COLUMNS_COUNT = 1000 -PLANOGRAMS_COUNT = 1000 +COLUMNS_COUNT = 100 +PLANOGRAMS_COUNT = 100 class ColumnsInputFactory(ModelFactory): diff --git a/benchmark/pydantic_benchmark/models.py b/benchmark/pydantic_benchmark/models.py index e779b6b..6c8e606 100644 --- a/benchmark/pydantic_benchmark/models.py +++ b/benchmark/pydantic_benchmark/models.py @@ -25,22 +25,19 @@ class CorrelationId(BaseModel): class ColumnsInput(BaseModel): column_number: StrictSmallInt = Field( - alias="columnNumber", description="View index in Televend" + description="View index in Televend", ) external_product_id: Optional[str] = Field( default=None, - alias="externalProductId", description="Product or Component external ID used for product/component identification in external partner's ERP system", min_length=1, max_length=32, ) old_qty: Optional[QuantityInt] = Field( default_factory=lambda: None, - alias="oldQty", ) new_qty: Optional[QuantityInt] = Field( default_factory=lambda: None, - alias="newQty", ) old_price: Optional[float] = Field( @@ -56,13 +53,10 @@ class ColumnsInput(BaseModel): le=99999999.99, ) - select_map: Optional[List[StrictSmallInt]] = Field( - default_factory=lambda: None, alias="selectMap" - ) + select_map: Optional[List[StrictSmallInt]] = Field(default_factory=lambda: None) item_type: Optional[ColumnItemType] = Field( default_factory=lambda: ColumnItemType.PRODUCT, - alias="itemType", description="MUST be set if item is COMPONENT", ) @@ -71,27 +65,6 @@ class ColumnsInput(BaseModel): alias_generator = to_camel_case str_strip_whitespace = True - # @root_validator - # def check_required_fields(cls, values): - # if values.get("external_product_id"): - # if values.get("old_qty") is None: - # raise ValueError( - # f"provide oldQty for product {values['external_product_id']}" - # ) - # if values.get("new_qty") is None: - # raise ValueError( - # f"provide newQty for product {values['external_product_id']}" - # ) - # if values.get("old_price") is None: - # raise ValueError( - # f"provide oldPrc for product {values['external_product_id']}" - # ) - # if values.get("new_price") is None: - # raise ValueError( - # f"provide newPrc for product {values['external_product_id']}" - # ) - # return values - @validator("item_type") def set_item_type(cls, value): return value or ColumnItemType.PRODUCT @@ -99,7 +72,6 @@ class ColumnsInput(BaseModel): class PlanogramInput(CorrelationId, BaseModel): machine_external_id: str = Field( - alias="machineExternalId", description="Machine external ID", min_length=1, max_length=32, @@ -124,15 +96,3 @@ class PlanogramsBulkInputPayload(BaseModel): class Config: populate_by_name = True alias_generator = to_camel_case - - # @root_validator - # def check_machine_unique(cls, values): - # planograms = values.get("planograms", []) - # external_ids = set() - # for planogram in planograms: - # if planogram.machine_external_id in external_ids: - # raise ValueError( - # f"Machine externalId must be unique! Duplicate {planogram.machine_external_id}" - # ) - # external_ids.add(planogram.machine_external_id) - # return values diff --git a/main.py b/main.py index 5865f61..0a40555 100644 --- a/main.py +++ b/main.py @@ -5,16 +5,17 @@ from benchmark.pydantic_benchmark.benchmark import PydanticBenchmark TEST_DATA_FILE = Path("test_data.json") +BIG_TEST_DATA_FILE = Path("test_data-big.json") -def main() -> None: - pydantic_benchmark = PydanticBenchmark(TEST_DATA_FILE) +def main(test_file: Path) -> None: + pydantic_benchmark = PydanticBenchmark(test_file) pydantic_benchmark.execute() - msgspec_benchmark = MsgSpecBenchmark(TEST_DATA_FILE) + msgspec_benchmark = MsgSpecBenchmark(test_file) msgspec_benchmark.execute() if __name__ == "__main__": # create_test_file(TEST_DATA_FILE) - main() + main(TEST_DATA_FILE)