summaryrefslogtreecommitdiff
path: root/tests/benchmarks
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-09-18 09:57:42 -0300
committerdrebs <drebs@riseup.net>2017-09-20 18:55:59 -0300
commitdac9c79e1c3adaa118794f92b29f97d009478589 (patch)
tree236fc18a36631fcdbe5f5eccbc9730145cd62f63 /tests/benchmarks
parent2ee61596f334c3358cbc825ab11d36b6488cd376 (diff)
[test] remove dependency on numpy
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/conftest.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/tests/benchmarks/conftest.py b/tests/benchmarks/conftest.py
index 80eccb08..2755ee48 100644
--- a/tests/benchmarks/conftest.py
+++ b/tests/benchmarks/conftest.py
@@ -1,5 +1,4 @@
import functools
-import numpy
import os
import psutil
import pytest
@@ -70,6 +69,18 @@ def txbenchmark_with_setup(monitored_benchmark_with_setup):
# resource monitoring
#
+def _mean(l):
+ return float(sum(l)) / len(l)
+
+
+def _std(l):
+ if len(l) <= 1:
+ return 0
+ mean = _mean(l)
+ squares = [(x - mean) ** 2 for x in l]
+ return (sum(squares) / (len(l) - 1)) ** 0.5
+
+
class ResourceWatcher(threading.Thread):
sampling_interval = 0.1
@@ -102,14 +113,17 @@ class ResourceWatcher(threading.Thread):
self.cpu_percent = self.process.cpu_percent()
# save memory usage info
if self.watch_memory:
+ stats = {
+ 'max': max(self.memory_samples),
+ 'min': min(self.memory_samples),
+ 'mean': _mean(self.memory_samples),
+ 'std': _std(self.memory_samples),
+ }
memory_percent = {
'sampling_interval': self.sampling_interval,
'samples': self.memory_samples,
- 'stats': {},
+ 'stats': stats,
}
- for stat in 'max', 'min', 'mean', 'std':
- fun = getattr(numpy, stat)
- memory_percent['stats'][stat] = fun(self.memory_samples)
self.memory_percent = memory_percent