File: performance.py

package info (click to toggle)
pyglet 2.0.17%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,560 kB
  • sloc: python: 80,579; xml: 50,988; ansic: 171; makefile: 146
file content (27 lines) | stat: -rw-r--r-- 497 bytes parent folder | download | duplicates (3)
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
"""
Performance measurement utilities.
"""
import pytest
import time


class PerformanceTimer:
    def __init__(self, max_time):
        self.max_time = max_time
        self.start_time = None

    def __enter__(self):
        self.start_time = time.time()

    def __exit__(self, exc_type, exc_val, exc_tb):
        assert time.time() - self.start_time < self.max_time


class PerformanceFixture:
    timer = PerformanceTimer


@pytest.fixture
def performance():
    return PerformanceFixture()