From 96ba3c135083b142dd224558ff167f2d744df99c Mon Sep 17 00:00:00 2001 From: Dominik Gasparic <56818232+codedoga@users.noreply.github.com> Date: Thu, 20 Oct 2022 23:59:51 +0200 Subject: [PATCH 1/3] Update test_i.py updating all objects with one query is usually faste --- benchmarks/django/simple/test_i.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/benchmarks/django/simple/test_i.py b/benchmarks/django/simple/test_i.py index acda7b6..b417a04 100644 --- a/benchmarks/django/simple/test_i.py +++ b/benchmarks/django/simple/test_i.py @@ -8,23 +8,19 @@ import time from random import choice -from django.db import transaction from simple.models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] - -objs = list(Journal.objects.all()) +objs = Journal.objects.all() count = len(objs) start = time.time() - -with transaction.atomic(): - for obj in objs: +for obj in objs: obj.level = choice(LEVEL_CHOICE) obj.text = f"{obj.text} Update" - obj.save() +Journal.objects.bulk_update(objs, ['level', 'text']) now = time.time() print(f"Django, I: Rows/sec: {count / (now - start): 10.2f}") From c99ab9ca24a9ed812781e1ab5a3db646bbc8188c Mon Sep 17 00:00:00 2001 From: Dominik Gasparic <56818232+codedoga@users.noreply.github.com> Date: Fri, 21 Oct 2022 00:14:06 +0200 Subject: [PATCH 2/3] Update test_i.py --- benchmarks/django/simple/test_i.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/django/simple/test_i.py b/benchmarks/django/simple/test_i.py index b417a04..6ed1743 100644 --- a/benchmarks/django/simple/test_i.py +++ b/benchmarks/django/simple/test_i.py @@ -12,7 +12,7 @@ LEVEL_CHOICE = [10, 20, 30, 40, 50] -objs = Journal.objects.all() +objs = list(Journal.objects.all()) count = len(objs) start = time.time() From ff6254823a0b4f34145dd174bc74472a7636ef13 Mon Sep 17 00:00:00 2001 From: Dominik Gasparic <56818232+codedoga@users.noreply.github.com> Date: Fri, 21 Oct 2022 00:14:33 +0200 Subject: [PATCH 3/3] Update test_j.py --- benchmarks/django/simple/test_j.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/benchmarks/django/simple/test_j.py b/benchmarks/django/simple/test_j.py index e417114..27eee43 100644 --- a/benchmarks/django/simple/test_j.py +++ b/benchmarks/django/simple/test_j.py @@ -8,7 +8,6 @@ import time from random import choice -from django.db import transaction from simple.models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] @@ -18,12 +17,10 @@ count = len(objs) start = time.time() - -with transaction.atomic(): - for obj in objs: +for obj in objs: obj.level = choice(LEVEL_CHOICE) - obj.save(update_fields=["level"]) +Journal.objects.bulk_update(objs, ['level']) now = time.time() print(f"Django, J: Rows/sec: {count / (now - start): 10.2f}")