1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-06-29 09:50:54 +02:00

add timed decorator for perf tracking

This commit is contained in:
Pierre-antoine Comby
2020-05-25 01:12:31 +02:00
parent 996ac3c337
commit f367b0ab2a
3 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python3
import json
import time
from collections import defaultdict
from django.core.management.base import BaseCommand
from collections import defaultdict
@ -10,6 +12,20 @@ from django.db import transaction
from polymorphic.models import PolymorphicModel
def timed(method):
""""
A simple decorator to measure time elapsed in class function (hence the args[0])
"""
def _timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
args[0].print_success(f"{method.__name__} executed ({te-ts:.2f}s)")
return result
return _timed
class ImportCommand(BaseCommand):
"""
Generic command for import of NK15 database