Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import json
  4.  
  5.  
  6. def _plot(members, python_versions, label):
  7. N = len(python_versions)
  8.  
  9. fig, ax = plt.subplots()
  10.  
  11. ind = np.arange(N) # the x locations for the groups
  12. width = 0.35 # the width of the bars
  13. p1 = ax.bar(ind, members['avro'], width, color='r')
  14.  
  15. p2 = ax.bar(ind + width, members['fastavro'], width,
  16. color='b')
  17.  
  18. ax.set_title('{} OPS by avro library and python version'.format(label))
  19. ax.set_xticks(ind + width / 2)
  20. ax.set_xticklabels(python_versions)
  21.  
  22. ax.legend((p1[0], p2[0]), ('avro', 'fastavro'))
  23. ax.autoscale_view()
  24.  
  25. plt.show()
  26.  
  27.  
  28. def _get_ops(_type, python_versions):
  29. fastavro_ops = []
  30. avro_ops = []
  31. for python_version in python_versions:
  32. with open(".benchmark-{}".format(python_version)) as f:
  33. data = json.load(f)
  34. for benchmark in data["benchmarks"]:
  35. if benchmark["group"] == _type:
  36. if "fastavro" in benchmark["name"]:
  37. fastavro_ops.append(benchmark["stats"]["ops"])
  38. else:
  39. avro_ops.append(benchmark["stats"]["ops"])
  40. return {
  41. "avro": avro_ops,
  42. "fastavro": fastavro_ops
  43. }
  44.  
  45.  
  46. if __name__ == "__main__":
  47. python_versions = ['pypy', 'pypy3', 'python2.7', 'python3.5', 'python3.6']
  48.  
  49. _plot(
  50. members=_get_ops("encoders", python_versions),
  51. python_versions=python_versions,
  52. label="writer"
  53. )
  54.  
  55. _plot(
  56. members=_get_ops("decoders", python_versions),
  57. python_versions=python_versions,
  58. label="reader"
  59. )
Add Comment
Please, Sign In to add comment