-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_b.py
31 lines (22 loc) · 862 Bytes
/
test_b.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
import asyncio
import os
import time
from random import choice
from models import Journal, engine
from sqlalchemy.ext.asyncio import AsyncSession
LEVEL_CHOICE = [10, 20, 30, 40, 50]
concurrents = int(os.environ.get("CONCURRENTS", "10"))
count = int(os.environ.get("ITERATIONS", "1000"))
count = int(count // concurrents) * concurrents
async def _runtest(count):
async with AsyncSession(engine) as session:
for i in range(count):
session.add(
Journal(level=choice(LEVEL_CHOICE), text=f"Insert from B, item {i}")
)
await session.commit()
async def runtest(loopstr):
start = now = time.time()
await asyncio.gather(*[_runtest(count // concurrents) for _ in range(concurrents)])
now = time.time()
print(f"Async SQLAlchemy ORM{loopstr}, B: Rows/sec: {count / (now - start): 10.2f}")