github.com/tomwright/dasel@v1.27.3/benchmark/plot_barchart.py (about)

     1  #!/usr/bin/env python
     2  
     3  import argparse
     4  import json
     5  import matplotlib.pyplot as plt
     6  
     7  parser = argparse.ArgumentParser(description=__doc__)
     8  parser.add_argument("file", help="JSON file with benchmark results")
     9  parser.add_argument("--title", help="Plot title")
    10  parser.add_argument("--out", help="Outfile file")
    11  args = parser.parse_args()
    12  
    13  with open(args.file) as f:
    14      results = json.load(f)["results"]
    15  
    16  x = ["dasel", "jq", "yq"]
    17  x_pos = [i for i, _ in enumerate(x)]
    18  
    19  # mean is in seconds. convert to ms.
    20  mean_times = [b["mean"] * 1000 for b in results]
    21  
    22  plt.bar(x_pos, mean_times, color='green', align='center')
    23  
    24  plt.ylabel("Execution Time (ms)")
    25  if args.title is not None:
    26      plt.title(args.title)
    27  
    28  plt.xticks(x_pos, x, horizontalalignment='center')
    29  
    30  plt.savefig(args.out, dpi=None, facecolor='w', edgecolor='w',
    31              orientation='portrait', format=None,
    32              transparent=False, bbox_inches=None, pad_inches=0.1)