Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- import json
- def _plot(members, python_versions, label):
- N = len(python_versions)
- fig, ax = plt.subplots()
- ind = np.arange(N) # the x locations for the groups
- width = 0.35 # the width of the bars
- p1 = ax.bar(ind, members['avro'], width, color='r')
- p2 = ax.bar(ind + width, members['fastavro'], width,
- color='b')
- ax.set_title('{} OPS by avro library and python version'.format(label))
- ax.set_xticks(ind + width / 2)
- ax.set_xticklabels(python_versions)
- ax.legend((p1[0], p2[0]), ('avro', 'fastavro'))
- ax.autoscale_view()
- plt.show()
- def _get_ops(_type, python_versions):
- fastavro_ops = []
- avro_ops = []
- for python_version in python_versions:
- with open(".benchmark-{}".format(python_version)) as f:
- data = json.load(f)
- for benchmark in data["benchmarks"]:
- if benchmark["group"] == _type:
- if "fastavro" in benchmark["name"]:
- fastavro_ops.append(benchmark["stats"]["ops"])
- else:
- avro_ops.append(benchmark["stats"]["ops"])
- return {
- "avro": avro_ops,
- "fastavro": fastavro_ops
- }
- if __name__ == "__main__":
- python_versions = ['pypy', 'pypy3', 'python2.7', 'python3.5', 'python3.6']
- _plot(
- members=_get_ops("encoders", python_versions),
- python_versions=python_versions,
- label="writer"
- )
- _plot(
- members=_get_ops("decoders", python_versions),
- python_versions=python_versions,
- label="reader"
- )
Add Comment
Please, Sign In to add comment