• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yeliudev / nncore / 8693025053

15 Apr 2024 04:54PM UTC coverage: 15.691% (+0.02%) from 15.676%
8693025053

push

github

yeliudev
Support setting split when testing

2 of 9 new or added lines in 3 files covered. (22.22%)

2 existing lines in 1 file now uncovered.

678 of 4321 relevant lines covered (15.69%)

3.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.46
/nncore/utils/timer.py
1
# Copyright (c) Ye Liu. Licensed under the MIT License.
2

3
from time import perf_counter
20✔
4

5

6
class Timer(object):
20✔
7
    """
8
    A flexible timer class.
9
    """
10

11
    def __init__(self):
20✔
12
        self.reset()
×
13

14
    def reset(self):
20✔
15
        """
16
        Reset the timer.
17
        """
18
        self._start = perf_counter()
×
19
        self._paused = None
×
20
        self._paused_time = 0
×
21

22
    def is_paused(self):
20✔
23
        """
24
        Check whether the timer is paused.
25
        """
26
        return self._paused is not None
×
27

28
    def pause(self):
20✔
29
        """
30
        Pause the timer.
31
        """
32
        if self.is_paused():
×
NEW
33
            raise RuntimeError('the timer that is already paused')
×
34

35
        self._paused = perf_counter()
×
36

37
    def resume(self):
20✔
38
        """
39
        Resume the timer.
40
        """
41
        if not self.is_paused():
×
NEW
42
            raise RuntimeError('the timer is not paused')
×
43

44
        self._paused_time += perf_counter() - self._paused
×
45
        self._paused = None
×
46

47
    def seconds(self):
20✔
48
        """
49
        Return the total number of seconds since the reset of the timer,
50
        excluding the time when the timer is paused.
51
        """
52
        end_time = self._paused or perf_counter()
×
53
        return end_time - self._start - self._paused_time
×
54

55
    def minutes(self):
20✔
56
        """
57
        Return the total number of minutes since the reset of the timer,
58
        excluding the time when the timer is paused.
59
        """
60
        return self.seconds() / 60
×
61

62
    def hours(self):
20✔
63
        """
64
        Return the total number of hours since the reset of the timer,
65
        excluding the time when the timer is paused.
66
        """
67
        return self.minutes() / 60
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc