1. Christian Heimes
  2. pep-456-benchmarks

Commits

Christian Heimes  committed 924e96a

add trivial analyzer

  • Participants
  • Parent commits eea1561
  • Branches default

Comments (0)

Files changed (1)

File analyze.py

View file
  • Ignore whitespace
+#!/usr/bin/env python3.3
+"""Trivial analyzer
+"""
+import os
+import csv
+
+def findcsv():
+    for root, dirs, files in os.walk("."):
+        if ".hg" in dirs:
+            dirs.remove(".hg")
+        for fname in files:
+            if fname.endswith(".csv"):
+                yield os.path.join(root, fname)
+
+def readcsv(fname):
+    with open(fname) as f:
+        reader = csv.DictReader(f)
+        for row in reader:
+            yield row["Benchmark"], float(row["Base"]), float(row["Changed"])
+
+def analyze(lines):
+    base = sum(line[1] for line in lines)
+    changed = sum(line[2] for line in lines)
+    return base, changed, (changed/base - 1)*100.
+
+def main():
+    fmt = "{:<40}\t{: 1.4f}\t{: 1.4f}\t{: 1.1f}%"
+    print("{:<40}\t {}\t\t {}\t {}".format("filename", "base", "changed", "diff %"))
+    for fname in findcsv():
+        lines = list(readcsv(fname))
+        print(fmt.format(fname, *analyze(lines)))
+
+if __name__ == "__main__":
+    main()