Skip to content

Commit 6bb7cfc

Browse files
committed
test: add helper methods to test perf
1 parent ecbd49b commit 6bb7cfc

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/trame_vtklocal/module/protocol.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
from functools import wraps
13
import zipfile
24
import json
35
from pathlib import Path
@@ -30,6 +32,21 @@ def map_id_mtime(object_manager, vtk_id):
3032
return (vtk_id, vtk_obj.GetMTime())
3133

3234

35+
def timeIt(func):
36+
"""A decorator to measure the execution time of a function."""
37+
38+
@wraps(func)
39+
def wrapper(*args, **kwargs):
40+
start_time = time.perf_counter()
41+
result = func(*args, **kwargs)
42+
end_time = time.perf_counter()
43+
execution_time = end_time - start_time
44+
print(f"{func.__name__}: {execution_time:.2f}s")
45+
return result
46+
47+
return wrapper
48+
49+
3350
class ObjectManagerAPI(LinkProtocol):
3451
def __init__(self, *args, **kwargs):
3552
addon_serdes_registrars = kwargs.pop("addon_serdes_registrars", [])

0 commit comments

Comments
 (0)