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:
@ -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
|
||||
|
Reference in New Issue
Block a user