-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_d.py
44 lines (33 loc) · 1.09 KB
/
test_d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncio
import os
import time
from random import choice
from models import Journal, engine
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
LEVEL_CHOICE = [10, 20, 30, 40, 50]
concurrents = int(os.environ.get("CONCURRENTS", "10"))
async def _runtest(inrange):
count = 0
async with AsyncSession(engine) as session:
for _ in range(inrange):
for level in LEVEL_CHOICE:
res = (
(
await session.execute(
select(Journal).where(Journal.level == level)
)
)
.scalars()
.all()
)
count += len(res)
return count
async def runtest(loopstr):
inrange = 10 // concurrents
if inrange < 1:
inrange = 1
start = now = time.time()
count = sum(await asyncio.gather(*[_runtest(inrange) for _ in range(concurrents)]))
now = time.time()
print(f"Async SQLAlchemy ORM{loopstr}, D: Rows/sec: {count / (now - start): 10.2f}")