Mercurial > hg > orthanc-tests
diff PerfsDb/TestResult.py @ 156:f1a75985caa8
first Db test framework - work in progress
author | am@osimis.io |
---|---|
date | Thu, 16 Aug 2018 17:13:32 +0200 |
parents | |
children | 85a2074f8794 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PerfsDb/TestResult.py Thu Aug 16 17:13:32 2018 +0200 @@ -0,0 +1,36 @@ +import time +import statistics +from orthancRestApi import OrthancClient + +class TestResult: + + def __init__(self, name: str): + self.minTimeInMs = 0 + self.maxTimeInMs = 0 + self.averageTimeInMs = 0 + self.name = name + self._durations = [] + + def add(self, durationInMs: float): + self._durations.append(durationInMs) + + def compute(self): + + mean = statistics.mean(self._durations) + stdDev = statistics.stdev(self._durations) + + # remove outliers + cleanedDurations = [x for x in self._durations if (x > mean - 2*stdDev) and (x < mean + 2*stdDev)] + + self.averageTimeInMs = statistics.mean(cleanedDurations) + self.minTimeInMs = min(cleanedDurations) + self.maxTimeInMs = max(cleanedDurations) + + + def __str__(self): + return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format( + name=self.name, + avg = self.averageTimeInMs, + min=self.minTimeInMs, + max=self.maxTimeInMs + ) \ No newline at end of file