Files
ormar/benchmarks/test_benchmark_bulk_create.py
erichaydel 7c18fa55e7 Add benchmarking test suite and greatly improve performance in a few cases (#948)
* Add benchmarking test suite

* Improve amortized time of model relation loads with a large number of rows

* Improve performance of loading models with many related models

* Improve performance of loading models with many related models to O(N)ish

* Fix bug where N model creation with shared related model would build in N^2 time

* Lower blocking time for queryset results

* Add docstrings and streamline hash code

Co-authored-by: haydeec1 <Eric.Haydel@jhuapl.edu>
2022-12-10 17:12:11 +01:00

27 lines
670 B
Python

import random
import string
import pytest
from benchmarks.conftest import Author
pytestmark = pytest.mark.asyncio
@pytest.mark.parametrize("num_models", [10, 20, 40])
async def test_making_and_inserting_models_in_bulk(aio_benchmark, num_models: int):
@aio_benchmark
async def make_and_insert(num_models: int):
authors = [
Author(
name="".join(random.sample(string.ascii_letters, 5)),
score=random.random() * 100,
)
for i in range(0, num_models)
]
assert len(authors) == num_models
await Author.objects.bulk_create(authors)
make_and_insert(num_models)