* 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>
27 lines
670 B
Python
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)
|