ScoDoc/tests/bench/notes_table.py

57 lines
1.8 KiB
Python
Raw Normal View History

# Simple benchmark
# mesure temps execution NotesTable
import time
from flask import g
from flask_login import login_user
2022-04-01 16:08:59 +02:00
from app.models import FormSemestre
from config import RunningConfig as BenchConfig
import app
from app import db, create_app
from app import clear_scodoc_cache
from app.auth.models import get_super_admin
from app.scodoc import notesdb as ndb
2022-04-01 16:08:59 +02:00
from app.comp.res_compat import NotesTableCompat
from app.comp import res_sem
def setup_generator(dept: str):
2022-04-01 16:08:59 +02:00
"setup app"
# Setup
apptest = create_app(BenchConfig)
# Run tests:
with apptest.test_client() as client:
with apptest.app_context():
with apptest.test_request_context():
# Clear application cache:
print("clearing cache...")
clear_scodoc_cache()
# initialize scodoc "g":
g.stored_get_formsemestre = {}
# Loge l'utilisateur super-admin
admin_user = get_super_admin()
login_user(admin_user)
app.set_sco_dept(dept) # set db connection
yield client
ndb.close_db_connection()
# Teardown:
db.session.commit()
db.session.remove()
def bench_notes_table(dept: str, formsemestre_ids: list[int]) -> float:
2022-04-01 16:08:59 +02:00
"benchmark note stable"
for client in setup_generator(dept):
tot_time = 0.0
for formsemestre_id in formsemestre_ids:
print(f"building sem {formsemestre_id}...")
2022-04-01 16:08:59 +02:00
formsemestre = FormSemestre.query.get(formsemestre_id)
t0 = time.time()
2022-04-01 16:08:59 +02:00
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
tot_time += time.time() - t0
print(f"Total time: {tot_time}")
return tot_time