Author: David Schneider <[email protected]>
Branch: extradoc
Changeset: r4322:3ac40db63536
Date: 2012-07-23 14:18 +0200
http://bitbucket.org/pypy/extradoc/changeset/3ac40db63536/
Log: add a tool to build latex tables from the csv data output of
difflogs.py
diff --git a/talk/vmil2012/tool/build_tables.py
b/talk/vmil2012/tool/build_tables.py
new file mode 100644
--- /dev/null
+++ b/talk/vmil2012/tool/build_tables.py
@@ -0,0 +1,61 @@
+from __future__ import division
+import csv
+import django
+from django.template import Template, Context
+import optparse
+from os import path
+import sys
+
+#
+
+
+def main(csvfile, template, texfile):
+ with open(csvfile, 'rb') as f:
+ reader = csv.DictReader(f, delimiter=',')
+ lines = [l for l in reader]
+
+ head = ['Benchmark',
+ 'number of operations before optimization',
+ '\\% guards before optimization',
+ 'number of operations after optimization',
+ '\\% guards after optimization',]
+
+ table = []
+ # collect data
+ for bench in lines:
+ keys = 'numeric guard set get rest new'.split()
+ ops_bo = sum(int(bench['%s before' % s]) for s in keys)
+ ops_ao = sum(int(bench['%s after' % s]) for s in keys)
+ res = [
+ bench['bench'],
+ ops_bo,
+ "%.2f (%s)" % (int(bench['guard before']) / ops_bo * 100,
bench['guard before']),
+ ops_ao,
+ "%.2f (%s)" % (int(bench['guard after']) / ops_ao * 100,
bench['guard after']),
+ ]
+ table.append(res)
+ output = render_table(template, head, table)
+ # Write the output to a file
+ with open(texfile, 'w') as out_f:
+ out_f.write(output)
+
+
+def render_table(ttempl, head, table):
+ # This line is required for Django configuration
+ django.conf.settings.configure()
+ # open and read template
+ with open(ttempl) as f:
+ t = Template(f.read())
+ c = Context({"head": head, "table": table})
+ return t.render(c)
+
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser(usage="%prog csvfile template.tex
output.tex")
+ options, args = parser.parse_args()
+ if len(args) < 3:
+ parser.print_help()
+ sys.exit(2)
+ else:
+ main(args[0], args[1], args[2])
+
diff --git a/talk/vmil2012/tool/setup.sh b/talk/vmil2012/tool/setup.sh
new file mode 100755
--- /dev/null
+++ b/talk/vmil2012/tool/setup.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+VENV=paper_env
+if [ ! -d "$VENV" ]; then
+ virtualenv "${VENV}"
+ source "${VENV}/bin/activate"
+ pip install django
+ echo "virtualenv created in ${VENV}"
+else
+ echo "virtualenv already present in ${VENV}"
+fi
+
diff --git a/talk/vmil2012/tool/table_template.tex
b/talk/vmil2012/tool/table_template.tex
new file mode 100644
--- /dev/null
+++ b/talk/vmil2012/tool/table_template.tex
@@ -0,0 +1,26 @@
+\begin{table}
+ \centering
+ \begin{tabular}{ {%for c in head %} |l| {% endfor %} }
+ \hline
+ {% for col in head %}
+ \textbf{ {{col}} }
+ {% if not forloop.last %}
+ &
+ {% endif %}
+ {% endfor %}
+ \\
+ \hline
+ {% for row in table %}
+ {% for cell in row %}
+ {{cell}}
+ {% if not forloop.last %}
+ &
+ {% endif %}
+ {% endfor %}
+ \\
+ {% endfor %}
+ \hline
+ \end{tabular}
+ \caption{'fff'}
+ \label{'fff'}
+\end{table}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit