156
|
1 import time
|
|
2 import statistics
|
|
3 from orthancRestApi import OrthancClient
|
|
4
|
|
5 class TestResult:
|
|
6
|
|
7 def __init__(self, name: str):
|
|
8 self.minTimeInMs = 0
|
|
9 self.maxTimeInMs = 0
|
|
10 self.averageTimeInMs = 0
|
|
11 self.name = name
|
|
12 self._durations = []
|
|
13
|
|
14 def add(self, durationInMs: float):
|
|
15 self._durations.append(durationInMs)
|
|
16
|
|
17 def compute(self):
|
|
18
|
169
|
19 if len(self._durations) >= 2:
|
|
20 mean = statistics.mean(self._durations)
|
|
21 stdDev = statistics.stdev(self._durations)
|
156
|
22
|
169
|
23 # remove outliers
|
|
24 cleanedDurations = [x for x in self._durations if (x > mean - 2*stdDev) and (x < mean + 2*stdDev)]
|
|
25
|
|
26 self.averageTimeInMs = statistics.mean(cleanedDurations)
|
|
27 self.minTimeInMs = min(cleanedDurations)
|
|
28 self.maxTimeInMs = max(cleanedDurations)
|
|
29 elif len(self._durations) == 1:
|
|
30 self.averageTimeInMs = self._durations[0]
|
|
31 self.minTimeInMs = self._durations[0]
|
|
32 self.maxTimeInMs = self._durations[0]
|
|
33 else:
|
|
34 raise ArithmeticError # you need at least one measure !
|
156
|
35
|
169
|
36
|
156
|
37
|
|
38 def __str__(self):
|
|
39 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format(
|
|
40 name=self.name,
|
|
41 avg = self.averageTimeInMs,
|
|
42 min=self.minTimeInMs,
|
|
43 max=self.maxTimeInMs
|
|
44 ) |