2021-10-15 14:00:51 +02:00
|
|
|
# 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
|
2021-10-15 14:00:51 +02:00
|
|
|
|
|
|
|
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
|
2021-10-15 14:00:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
def setup_generator(dept: str):
|
2022-04-01 16:08:59 +02:00
|
|
|
"setup app"
|
2021-10-15 14:00:51 +02:00
|
|
|
# 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"
|
2021-10-15 14:00:51 +02:00
|
|
|
for client in setup_generator(dept):
|
|
|
|
tot_time = 0.0
|
|
|
|
for formsemestre_id in formsemestre_ids:
|
|
|
|
print(f"building sem {formsemestre_id}...")
|
2023-03-20 11:17:38 +01:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2021-10-15 14:00:51 +02:00
|
|
|
t0 = time.time()
|
2022-04-01 16:08:59 +02:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2021-10-15 14:00:51 +02:00
|
|
|
tot_time += time.time() - t0
|
|
|
|
print(f"Total time: {tot_time}")
|
|
|
|
return tot_time
|