fill_performance.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env python3
  2. # Copyright Hans Dembinski 2018 - 2019.
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt or copy at
  5. # https://www.boost.org/LICENSE_1_0.txt)
  6. import os
  7. import numpy as np
  8. import glob
  9. import re
  10. import json
  11. import sys
  12. from collections import defaultdict, OrderedDict
  13. from matplotlib.patches import Rectangle
  14. from matplotlib.lines import Line2D
  15. from matplotlib.text import Text
  16. from matplotlib.font_manager import FontProperties
  17. import matplotlib.pyplot as plt
  18. import matplotlib as mpl
  19. mpl.rcParams.update(mpl.rcParamsDefault)
  20. cpu_frequency = 0
  21. data = defaultdict(lambda: [])
  22. for fn in sys.argv[1:]:
  23. d = json.load(open(fn))
  24. cpu_frequency = d["context"]["mhz_per_cpu"]
  25. for bench in d["benchmarks"]:
  26. name = bench["name"]
  27. time = min(bench["cpu_time"], bench["real_time"])
  28. m = re.match("fill_(n_)?([0-9])d<([^>]+)>", name)
  29. if m.group(1):
  30. time /= 1 << 15
  31. tags = m.group(3).split(", ")
  32. dim = int(m.group(2))
  33. label = re.search(
  34. "fill_([a-z]+)", os.path.splitext(os.path.split(fn)[1])[0]
  35. ).group(1)
  36. dist = tags[0]
  37. if len(tags) > 1 and tags[1] in ("dynamic_tag", "static_tag"):
  38. if len(tags) == 3 and "DStore" in tags[2]:
  39. continue
  40. label += "-" + {"dynamic_tag": "dyn", "static_tag": "sta"}[tags[1]]
  41. label += "-fill" if m.group(1) else "-call"
  42. data[dim].append((label, dist, time / dim))
  43. time_per_cycle_in_ns = 1.0 / (cpu_frequency * 1e6) / 1e-9
  44. plt.figure(figsize=(7, 6))
  45. i = 0
  46. for dim in sorted(data):
  47. v = data[dim]
  48. labels = OrderedDict()
  49. for label, dist, time in v:
  50. if label in labels:
  51. labels[label][dist] = time / time_per_cycle_in_ns
  52. else:
  53. labels[label] = {dist: time / time_per_cycle_in_ns}
  54. j = 0
  55. for label, d in labels.items():
  56. t1 = d["uniform"]
  57. t2 = d["normal"]
  58. i -= 1
  59. z = float(j) / len(labels)
  60. col = (1.0 - z) * np.array((1.0, 0.0, 0.0)) + z * np.array((1.0, 1.0, 0.0))
  61. if label == "root":
  62. col = "k"
  63. label = "ROOT 6"
  64. if "numpy" in label:
  65. col = "0.6"
  66. if "gsl" in label:
  67. col = "0.3"
  68. label = "GSL"
  69. tmin = min(t1, t2)
  70. tmax = max(t1, t2)
  71. r1 = Rectangle((0, i), tmax, 1, facecolor=col)
  72. r2 = Rectangle(
  73. (tmin, i), tmax - tmin, 1, facecolor="none", edgecolor="w", hatch="//////"
  74. )
  75. plt.gca().add_artist(r1)
  76. plt.gca().add_artist(r2)
  77. font = FontProperties(size=9)
  78. tx = Text(
  79. -0.5,
  80. i + 0.5,
  81. "%s" % label,
  82. fontproperties=font,
  83. va="center",
  84. ha="right",
  85. clip_on=False,
  86. )
  87. plt.gca().add_artist(tx)
  88. j += 1
  89. i -= 1
  90. font = FontProperties()
  91. font.set_weight("bold")
  92. tx = Text(
  93. -0.5,
  94. i + 0.6,
  95. "%iD" % dim,
  96. fontproperties=font,
  97. va="center",
  98. ha="right",
  99. clip_on=False,
  100. )
  101. plt.gca().add_artist(tx)
  102. plt.ylim(0, i)
  103. plt.xlim(0, 80)
  104. plt.tick_params("y", left=False, labelleft=False)
  105. plt.xlabel("average CPU cycles per random input value (smaller is better)")
  106. plt.tight_layout()
  107. plt.savefig("fill_performance.svg")
  108. plt.show()