summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2013-05-18 10:57:29 -0400
committerJohannes Weiner <hannes@cmpxchg.org>2013-05-18 11:00:37 -0400
commitc0f8fe14b31635684f259f1b67f05df8e7d6acbc (patch)
tree75e263fc205442704bbe9be7f67f0586f7a41c53
parent2e7ae097cc10611a620869a0ea6313ad20469654 (diff)
analyze: add min, median, max primitives
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rwxr-xr-xanalyze29
1 files changed, 28 insertions, 1 deletions
diff --git a/analyze b/analyze
index 3906bae..4140a58 100755
--- a/analyze
+++ b/analyze
@@ -12,6 +12,21 @@ def stddev(v):
d = [(n - m) ** 2 for n in v]
return math.sqrt(mean(d))
+def median(v):
+ s = sorted(v)
+ l = len(s)
+ m = l / 2
+ if l % 2:
+ return s[m]
+ else:
+ return mean([s[m - 1], s[m]])
+
+def min(v):
+ return sorted(v)[0]
+
+def max(v):
+ return sorted(v)[-1]
+
class Dataset(object):
def __init__(self, runs):
self.runs = runs
@@ -155,12 +170,24 @@ def builtin_stddev(s):
"""
return s.unary(lambda r: [stddev(r)])
+def builtin_min(s):
+ return s.unary(lambda r: [min(r)])
+
+def builtin_max(s):
+ return s.unary(lambda r: [max(r)])
+
+def builtin_median(s):
+ return s.unary(lambda r: [median(r)])
+
senv = { 'read': builtin_read,
'readdict': builtin_readdict,
'merge': builtin_merge,
'fold': builtin_fold,
'mean': builtin_mean,
- 'stddev': builtin_stddev }
+ 'stddev': builtin_stddev,
+ 'min': builtin_min,
+ 'max': builtin_max,
+ 'median': builtin_median }
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--spec', action='append', default=[])