I was trying to sample a few records from my queryset for performance like:
from random import sample
from my_app import MyModel
my_models = MyModel.objects.all()
# sample only a few of records for performance
my_models_sample = sample(my_models, 5)
for model in my_models_sample:
model.some_expensive_calculation
But I felt like it made only worse in terms of execution time.
How does random.sample()
actually works behind the scene? And will it be rather performance burden on django querysets?