File size: 513 Bytes
27ba426
 
 
 
 
 
 
 
87e8a82
27ba426
87e8a82
27ba426
 
87e8a82
 
 
27ba426
87e8a82
 
27ba426
87e8a82
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""⭐ Text Classification with Optimum and ONNXRuntime

Utils functions.

Author:
    - @ChainYo - https://github.com/ChainYo
"""

from contextlib import contextmanager
from time import time
from typing import List


@contextmanager
def calculate_inference_time(buffer: List[int]):
    """Calculate inference time.

    Args:
        buffer (list): List of inference times.

    Returns:
        float: Average inference time.
    """
    start = time()
    yield
    end = time()
    buffer.append(end - start)