Coverage for install/scipp/utils/profile.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-17 01:51 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Simon Heybrock 

4import os 

5import time as _time 

6 

7 

8def time(method): 

9 """Decorator that prints function run time.""" 

10 

11 def timed(*args, **kw): 

12 indent = time.counter 

13 time.counter += 1 

14 # Not using print() since output may be swallowed in Jupyter notebooks 

15 os.write(1, f'{" " * indent}enter {method.__name__}\n'.encode()) 

16 start = _time.time() 

17 result = method(*args, **kw) 

18 end = _time.time() 

19 ms = (end - start) * 1000 

20 time.counter -= 1 

21 os.write(1, f'{" " * indent}exit {method.__name__} {ms} ms\n'.encode()) 

22 return result 

23 

24 return timed 

25 

26 

27time.counter = 0