Skip to content

Commit 4e47cff

Browse files
authored
Add benchmarks for updating (#1881)
1 parent 1dd9def commit 4e47cff

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/benchmarks/test_update.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import asyncio
2+
import random
3+
4+
from tests.testmodels import BenchmarkFewFields, BenchmarkManyFields
5+
6+
7+
def test_update_few_fields_with_save(benchmark, few_fields_benchmark_dataset):
8+
loop = asyncio.get_event_loop()
9+
10+
@benchmark
11+
def bench():
12+
async def _bench():
13+
instance = random.choice(few_fields_benchmark_dataset) # nosec
14+
instance.level = random.randint(0, 100) # nosec
15+
instance.text = "updated " + str(random.randint(0, 100)) # nosec
16+
await instance.save()
17+
18+
loop.run_until_complete(_bench())
19+
20+
21+
def test_update_many_fields_with_save(
22+
benchmark, many_fields_benchmark_dataset, gen_many_fields_data
23+
):
24+
loop = asyncio.get_event_loop()
25+
26+
@benchmark
27+
def bench():
28+
async def _bench():
29+
instance = random.choice(many_fields_benchmark_dataset) # nosec
30+
rand_val = random.randint(0, 100) # nosec
31+
instance.col_float1 = random.uniform(0, 100) # nosec
32+
instance.col_smallint1 = rand_val
33+
instance.col_int1 = rand_val
34+
instance.col_bigint1 = rand_val
35+
instance.col_char1 = "updated " + str(rand_val)
36+
instance.col_text1 = "updated " + str(rand_val)
37+
await instance.save()
38+
39+
loop.run_until_complete(_bench())
40+
41+
42+
def test_update_few_fields_with_update(benchmark, few_fields_benchmark_dataset):
43+
loop = asyncio.get_event_loop()
44+
45+
@benchmark
46+
def bench():
47+
async def _bench():
48+
instance = random.choice(few_fields_benchmark_dataset) # nosec
49+
await BenchmarkFewFields.filter(id=instance.id).update(
50+
level=random.randint(0, 100), # nosec
51+
text="updated " + str(random.randint(0, 100)), # nosec
52+
)
53+
54+
loop.run_until_complete(_bench())
55+
56+
57+
def test_update_many_fields_with_update(
58+
benchmark, many_fields_benchmark_dataset, gen_many_fields_data
59+
):
60+
loop = asyncio.get_event_loop()
61+
62+
@benchmark
63+
def bench():
64+
async def _bench():
65+
instance = random.choice(many_fields_benchmark_dataset) # nosec
66+
rand_val = random.randint(0, 100) # nosec
67+
await BenchmarkManyFields.filter(id=instance.id).update(
68+
col_float1=random.uniform(0, 100), # nosec
69+
col_smallint1=rand_val,
70+
col_int1=rand_val,
71+
col_bigint1=rand_val,
72+
col_char1="updated " + str(rand_val),
73+
col_text1="updated " + str(rand_val),
74+
)
75+
76+
loop.run_until_complete(_bench())

0 commit comments

Comments
 (0)