Skip to content

Commit 560b988

Browse files
authored
more precise timer summary (#113)
* fix: use all timers in summary * fix: lint * chore: lint
1 parent ba0507a commit 560b988

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

devtools/timer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from time import time
1+
from time import perf_counter
22

33
__all__ = ('Timer',)
44

55
MYPY = False
66
if MYPY:
7-
from typing import Any, List, Optional, Set
7+
from typing import Any, List, Optional
88

99
# required for type hinting because I (stupidly) added methods called `str`
1010
StrType = str
@@ -15,10 +15,10 @@ def __init__(self, name: 'Optional[str]' = None, verbose: bool = True) -> None:
1515
self._name = name
1616
self.verbose = verbose
1717
self.finish: 'Optional[float]' = None
18-
self.start = time()
18+
self.start = perf_counter()
1919

2020
def capture(self) -> None:
21-
self.finish = time()
21+
self.finish = perf_counter()
2222

2323
def elapsed(self) -> float:
2424
if self.finish:
@@ -66,14 +66,14 @@ def capture(self, verbose: 'Optional[bool]' = None) -> 'TimerResult':
6666
print(r.str(self.dp), file=self.file, flush=True)
6767
return r
6868

69-
def summary(self, verbose: bool = False) -> 'Set[float]':
70-
times = set()
69+
def summary(self, verbose: bool = False) -> 'List[float]':
70+
times = []
7171
for r in self.results:
7272
if not r.finish:
7373
r.capture()
7474
if verbose:
7575
print(f' {r.str(self.dp)}', file=self.file)
76-
times.add(r.elapsed())
76+
times.append(r.elapsed())
7777

7878
if times:
7979
from statistics import mean, stdev

0 commit comments

Comments
 (0)