Source

pep-456-benchmarks / analyze.py

Full commit
#!/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 sorted(findcsv()):
        lines = list(readcsv(fname))
        print(fmt.format(fname, *analyze(lines)))

if __name__ == "__main__":
    main()