File size: 528 Bytes
da03eea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: UTF-8 -*-
"""
@Time : 28/05/2025 16:17
@Author : xiaoguangliang
@File : utils.py
@Project : Faice_text2face
"""
import time
from contextlib import contextmanager


@contextmanager
def timer(msg="all tasks"):
    """
    Calculate the time of running
    @return:
    """
    startTime = time.time()
    yield
    endTime = time.time()
    # print(f'The time cost for {msg}:{round(1000.0 * (endTime - startTime), 2)}, ms')
    print(f"The time cost for {msg}:", round((endTime - startTime) / 60, 2), "minutes")